// Arup Guha
// 3/3/2024
// Solution to SER 2023 D2 Problem E: Acceptable Seating Arrangements

import java.util.*;

public class e {

	public static int r;
	public static int c;
	
	public static int[] start;
	public static int[] end;
	
	public static int[] sMap;
	public static int[] eMap;
	
	public static void main(String[] args) {
	
		Scanner stdin = new Scanner(System.in);
		r = stdin.nextInt();
		c = stdin.nextInt();
		
		// Read start and store map.
		start = new int[r*c];
		sMap = new int[r*c];
		for (int i=0; i<r*c; i++) {
			start[i] = stdin.nextInt()-1;
			sMap[start[i]] = i;
		}
		
		// Same for end.
		end = new int[r*c];
		eMap = new int[r*c];
		for (int i=0; i<r*c; i++) {
			end[i] = stdin.nextInt()-1;
			eMap[end[i]] = i;
		}
		
		ArrayList<Integer> res = new ArrayList<Integer>();
		
		// i represents the number we want to move to its final place.
		for (int i=0; i<r*c; i++) {
		
			// Where we have to start and end.
			int sLoc = sMap[i];
			int sRow = sLoc/c;
			int eLoc = eMap[i];
			int eRow = eLoc/c;
			int curval = start[eLoc];
			
			// No work has to be done.
			if (curval == i) continue;
			
			// Just to make this easy to read.
			int oldLoc = sLoc;
			
			// We'll loop swaps, until we get i into its ending position.
			while (sMap[i] != eLoc) {
				
				// Mark is the column on the start row with the largest value less than 
				// the value we must swap with. It's safe to swap this with end val.
				int mark = sLoc%c;
				while (mark < c && start[sRow*c+mark] < curval) mark++;
				mark--;
				
				// Just swap each of these iteratively with the end location.
				for (int x=sRow*c+mark; x>=oldLoc; x--) {
					res.add(r*c*x + eLoc);
					swapStart(x, eLoc);
				}
			}
		}
		
		// Ta da!
		System.out.println(res.size());
		for (int i=0; i<res.size(); i++)
			outputMove(res.get(i));
	}
	
	// Swaps locations i and j in start, keeping start current.
	public static void swapStart(int i, int j) {
		int tmp = start[i];
		start[i] = start[j];
		start[j] = tmp;
		sMap[start[i]] = i;
		sMap[start[j]] = j;
	}
	
	// Outputs the move stored in code.
	public static void outputMove(int code) {
		int old = code/(r*c);
		int cur = code%(r*c);
		int oldx = old/c + 1;
		int oldy = old%c + 1;
		int curx = cur/c + 1;
		int cury = cur%c + 1;
		System.out.println(oldx+" "+oldy+" "+curx+" "+cury);
	}
}