public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int times = scan.nextInt();
		f: for (int i = 0; i < times; i++) {
			int l = scan.nextInt();
			int k = scan.nextInt();
			int[] array = new int[l];
			for (int j = l - k; j < array.length; j++)
				array[j] = 1;
			if (i != 0)
				sb.append("\n");
			sb.append(printArray(array)).append("\n");
			while (next_permutation(array))
				sb.append(printArray(array)).append("\n");
		}
		System.out.print(sb);
	}