/* Sample solution to Sylvester construction.
 * Author: Mikael Goldmann
 *
 * Method: The x,y entry of the matrix is -1 if and only if 
 *         the hamming weight of x&y is odd.
 *
 * Remark: 2^63 presents a slight problem if one uses signed 64-bit
 *         numbers. However, all numbers of a test case are strictly
 *         less than 2^63, except possibly n, but n is not needed to
 *         solve the problem.
 */

import java.io.*;

class sylvester
{
    static BufferedReader stdin;
    static PrintWriter stdout;
    
    public static void main(String[] ss) throws Exception
    {
	Reader rdr = new InputStreamReader(System.in);
	stdin      = new BufferedReader(rdr);
	Writer wtr = new OutputStreamWriter(System.out);
	wtr        = new BufferedWriter(wtr);
	stdout     = new PrintWriter(wtr);
	
	(new sylvester()).run();
	stdout.close();
    }
    
    /* Compute hamming weight of x */
    int hw(long x) 
    {
	int h=0;
	while (x>0) {
	    h += x&1;
	    x >>>=1;
	}
	return h;	
    }
    
    void run() throws Exception
    {
	int N = Integer.parseInt(stdin.readLine());
	for (int i = 0; i < N; ++i) solve(i+1);
    }
    

    /* Note: 2^63 is tricky for java, so I will just skip n */
    /* I am assuming that x+w <= n and y+h <= n             */
    void solve(int cnt) throws Exception
    {
	long x,y;
	int w,h;
	String s = stdin.readLine();
	java.util.StringTokenizer t = new java.util.StringTokenizer(s);	
	t.nextToken(); // just skip n (who needs it?)
	x = Long.parseLong(t.nextToken());
	y = Long.parseLong(t.nextToken());
	w = Integer.parseInt(t.nextToken());
	h = Integer.parseInt(t.nextToken());
	
	for (long y1=y; y1 < y+h; ++y1) {
	    for (long x1=x; x1 < x+w; ++x1) {	    
		if (x != x1) stdout.print(' ');
		stdout.print( 1 - 2*((hw(x1 & y1)) & 1));
	    }
	    stdout.println();
	}
	stdout.println();
    }
}

		
	    
	
