using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static int NN => int.Parse(ReadLine()); static int[] NList => ReadLine().Split().Select(int.Parse).ToArray(); static int[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray(); public static void Main() { Solve(); } static void Solve() { var t = NN; var ans = new List(); var map = new int[][] { new int[] { 0, 1, 1 }, new int[] { 1, 2, 2 }, new int[] { 1, 2, 2 }, }; for (var u = 0; u < t; ++u) { var c = NList; var (h, w) = (c[0], c[1]); var hoffset = h % 3 == 2 ? 1 : 0; var woffset = w % 3 == 2 ? 1 : 0; for (var i = 0; i < h; ++i) { var sub = new int[w]; for (var j = 0; j < w; ++j) sub[j] = map[(i + hoffset) % 3][(j + woffset) % 3]; ans.Add(string.Join(" ", sub)); } } WriteLine(string.Join("\n", ans)); } }