Problem: Vasiliy finally got to work, where there is a huge amount of tasks waiting for him. Vasiliy is given a matrix consisting of n rows and m columns and q tasks. Each task is to swap two submatrices of the given matrix.

For each task Vasiliy knows six integers ai, bi, ci, di, hi, wi, where ai is the index of the row where the top-left corner of the first rectangle is located, bi is the index of its column, ci is the index of the row of the top-left corner of the second rectangle, di is the index of its column, hi is the height of the rectangle and wi is its width.

It's guaranteed that two rectangles in one query do not overlap and do not touch, that is, no cell belongs to both rectangles, and no two cells belonging to different rectangles share a side. However, rectangles are allowed to share an angle.

Vasiliy wants to know how the matrix will look like after all tasks are performed.

Input

The first line of the input contains three integers n, m and q (2 ≤ n, m ≤ 1000, 1 ≤ q ≤ 10 000) — the number of rows and columns in matrix, and the number of tasks Vasiliy has to perform.

Then follow n lines containing m integers vi, j (1 ≤ vi, j ≤ 109) each — initial values of the cells of the matrix.

Each of the following q lines contains six integers ai, bi, ci, di, hi, wi (1 ≤ ai, ci, hi ≤ n, 1 ≤ bi, di, wi ≤ m).

Output

Print n lines containing m integers each — the resulting matrix.

Examples

Input

4 4 2
1 1 2 2
1 1 2 2
3 3 4 4
3 3 4 4
1 1 3 3 2 2
3 1 1 3 2 2


Output

4 4 3 3
4 4 3 3
2 2 1 1
2 2 1 1


Input

4 2 1
1 1
1 1
2 2
2 2
1 1 4 1 1 2


Output

2 2
1 1
2 2
1 1

Solution (in JAVA):

Solution:
import java.util.*;
import java.io.*;

public class A
{

    static int mod = (int) (1e9+7);
    static InputReader in;
    static PrintWriter out;
    static Cell[][] arr;
    
    static class Cell{
    	Cell left;
    	Cell right;
    	Cell up;
    	Cell down;
    	int val;
    	
    	public Cell(int val){
    		this.val = val;
    	}
    }
    
    static Cell get(int r, int c) {
    	Cell res = arr[0][0];
    	while(r-- > 0)
    		res = res.down;
    	while(c-- > 0)
    		res = res.right;
    	return res;
    }
    
    public static void main(String[] args)
    {
        in = new InputReader(System.in);
        out = new PrintWriter(System.out);            
        
        int n = in.nextInt();
        int m = in.nextInt();
        arr = new Cell[n + 2][m + 2];
        int q = in.nextInt();
        
        for(int i = 0; i <= n + 1; i++) {
        	for(int j = 0; j <= m + 1; j++) {
        		arr[i][j] = new Cell(0);
        	}
        }

        for(int i = 1; i <= n; i++) {
        	for(int j = 1; j <= m; j++) {
        		arr[i][j].val = in.nextInt();
        	}
        }
        
        for(int i = 0; i <= n + 1; i++) {
        	for(int j = 0; j <= m + 1; j++) {
        		if(i >= 1)
        			arr[i][j].up = arr[i - 1][j];
        		if(i <= n)
        			arr[i][j].down = arr[i + 1][j];
        		if(j >= 1)
        			arr[i][j].left = arr[i][j - 1];
        		if(j <= m)
        			arr[i][j].right = arr[i][j + 1];
        	}
        }
        
        while(q-- > 0) {
        	int a = in.nextInt();
        	int b = in.nextInt();
        	int c = in.nextInt();
        	int d = in.nextInt();
        	int h = in.nextInt();
        	int w = in.nextInt();

        	//debug(a,b,c,d);
        	Cell first = get(a, b);
        	Cell second = get(c, d);
        	
        	for(int i = 0; i < w; i++) {
        		first.up.down = second;
        		second.up.down = first;
        		Cell t = first.up;
        		first.up = second.up;
        		second.up = t;
        		if(i == w - 1) continue;
        		first = first.right;
        		second = second.right;
        	}
        	
        	for(int i = 0; i < h; i++) {
        		first.right.left = second;
        		second.right.left = first;
        		Cell t = first.right;
        		first.right = second.right;
        		second.right = t;
        		if(i == h - 1) continue;
        		first = first.down;
        		second = second.down;
        	}
        	
        	for(int i = 0; i < w; i++) {
        		first.down.up = second;
        		second.down.up = first;
        		Cell t = first.down;
        		first.down = second.down;
        		second.down = t;
        		if(i == w - 1) continue;
        		first = first.left;
        		second = second.left;
        	}
        	
        	for(int i = 0; i < h; i++) {
        		first.left.right = second;
        		second.left.right = first;
        		Cell t = first.left;
        		first.left = second.left;
        		second.left = t;
        		if(i == h - 1) continue;
        		first = first.up;
        		second = second.up;
        	}
        }
        
        for(int i = 1; i <= n; i++) {
        	Cell cur = arr[i][0];
        	for(int j = 1; j <= m; j++) {
        		cur = cur.right;
        		out.print(cur.val + " ");
        	}
        	out.println();
        }
        
        out.close();

    }


    static void debug(Object... o)
    {
            System.out.println(Arrays.deepToString(o));
    }

    static class Pair implements Comparable<Pair>
    {

        int x,y;
        
        
        Pair (int x,int y)
        {
		this.x = x;
                this.y = y;
	}
        
	public int compareTo(Pair o)
        {
            return Integer.compare(this.x,o.x);
		//return 0;
	}

        public boolean equals(Object o)
        {
            if (o instanceof Pair)
            {
                Pair p = (Pair)o;
                return p.x == x && p.y==y;
            }
            return false;
        }

        @Override
        public String toString()
        {
            return x + " "+ y;
        }
        
        public int hashCode()
        {
            return new Long(x).hashCode() * 31 + new Long(y).hashCode();
        }
    
    } 

    static long gcd(long x,long y)
    {
        if(y==0)
                return x;
        else
                return gcd(y,x%y);
    }

    static int gcd(int x,int y)
    {
        if(y==0)
                return x;
        else 
                return gcd(y,x%y);
    }

    static long pow(long n,long p,long m)
    {
         long  result = 1;
          if(p==0)
            return 1;

        while(p!=0)
        {
            if(p%2==1)
                result *= n;
            if(result>=m)
            result%=m;
            p >>=1;
            n*=n;
            if(n>=m)
            n%=m;
        }
        return result;
    }

    static long pow(long n,long p)
    {
        long  result = 1;
          if(p==0)
            return 1;

        while(p!=0)
        {
            if(p%2==1)
                result *= n;	    
            p >>=1;
            n*=n;	    
        }
        return result;
    }

    static class InputReader
    {

        private final InputStream stream;
        private final byte[] buf = new byte[8192];
        private int curChar, snumChars;
        private SpaceCharFilter filter;

        public InputReader(InputStream stream)
        {
                this.stream = stream;
        }

        public int snext()
        {
                if (snumChars == -1)
                        throw new InputMismatchException();
                if (curChar >= snumChars)
                {
                        curChar = 0;
                        try
                        {
                                snumChars = stream.read(buf);
                        } catch (IOException e)
                        {
                                throw new InputMismatchException();
                        }
                        if (snumChars <= 0)
                                return -1;
                }
                return buf[curChar++];
        }

        public int nextInt()
        {
                int c = snext();
                while (isSpaceChar(c))
                {
                        c = snext();
                }
                int sgn = 1;
                if (c == '-')
                {
                        sgn = -1;
                        c = snext();
                }
                int res = 0;
                do
                {
                        if (c < '0' || c > '9')
                                throw new InputMismatchException();
                        res *= 10;
                        res += c - '0';
                        c = snext();
                } while (!isSpaceChar(c));
                return res * sgn;
        }

        public long nextLong()
        {
                int c = snext();
                while (isSpaceChar(c))
                {
                        c = snext();
                }
                int sgn = 1;
                if (c == '-')
                {
                        sgn = -1;
                        c = snext();
                }
                long res = 0;
                do
                {
                        if (c < '0' || c > '9')
                                throw new InputMismatchException();
                        res *= 10;
                        res += c - '0';
                        c = snext();
                } while (!isSpaceChar(c));
                return res * sgn;
        }

        public int[] nextIntArray(int n)
        {
                int a[] = new int[n];
                for (int i = 0; i < n; i++)
                {
                        a[i] = nextInt();
                }
                return a;
        }

        public long[] nextLongArray(int n)
        {
                long a[] = new long[n];
                for (int i = 0; i < n; i++)
                {
                        a[i] = nextLong();
                }
                return a;
        }

        public String readString()
        {
                int c = snext();
                while (isSpaceChar(c))
                {
                        c = snext();
                }
                StringBuilder res = new StringBuilder();
                do
                {
                        res.appendCodePoint(c);
                        c = snext();
                } while (!isSpaceChar(c));
                return res.toString();
        }

        public String nextLine()
        {
                int c = snext();
                while (isSpaceChar(c))
                        c = snext();
                StringBuilder res = new StringBuilder();
                do
                {
                        res.appendCodePoint(c);
                        c = snext();
                } while (!isEndOfLine(c));
                return res.toString();
        }

        public boolean isSpaceChar(int c)
        {
                if (filter != null)
                        return filter.isSpaceChar(c);
                return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        private boolean isEndOfLine(int c)
        {
                return c == '\n' || c == '\r' || c == -1;
        }

        public interface SpaceCharFilter
        {
                public boolean isSpaceChar(int ch);
        }

    }
}