from itertools import combinations class dsu: n = 1 parent_or_size = [-1 for i in range(n)] def __init__(self, N): self.n = N self.parent_or_size = [-1 for i in range(N)] def merge(self, a, b): assert 0 <= a < self.n, "0<=a 0: result2.append(result[i]) return result2 WAYS = [(1, 0), (-1, 0), (0, 1), (0, -1)] def solve(): N, K = map(int, input().split()) for comb in combinations(range(N**2), K): comb_set = set(comb) uf = dsu(N**2) empty = set() for x in comb: i, j = x // N, x % N for di, dj in WAYS: ni, nj = i + di, j + dj nx = ni * N + nj if not (0 <= ni < N and 0 <= nj < N): continue if nx in comb_set: uf.merge(x, nx) else: empty.add(nx) if uf.size(comb[0]) != K: continue if len(empty) != K: continue print("Yes") for i in range(N): for j in range(N): if i * N + j in comb: print("#", end="") else: print(".", end="") print() return print("No") if __name__ == "__main__": T = int(input()) for _ in range(T): solve()