import java.util.*; import java.io.*; public class Main { public static Scanner sc = new Scanner(System.in); public static PrintWriter pw = new PrintWriter(System.out); public static void main(String[] args) { int t = sc.nextInt(); while( t > 0 ) { solve(); t--; } pw.flush(); } static void solve() { int H = sc.nextInt(); int W = sc.nextInt(); int[][] g = { {2,2,1}, {2,2,1}, {1,1,0} }; int idi = H%3 == 1 ? 2 : 0; int idj = W%3 == 1 ? 2 : 0; for( int i = 0; i < H; i++ ) { for( int j = 0; j < W; j++ ) { pw.print(g[(idi+i)%3][(idj+j)%3]+" "); } pw.println(); } pw.println(); } }