import java.util.*; import java.io.*; import java.text.*; class Main{ static final long MOD = (long)1e9+7; static final int MAX = (int)1e5+1; static FastReader in; public static void main(String[] args){ in = new FastReader(); StringBuilder out = new StringBuilder(""); int T = ni(); while(T-->0){ int N = ni(), M = ni(); //input grid int[][] grid = new int[N][M]; //if survive[i][j] = true, boolean[][] survive = new boolean[N][M]; //Max heap to process positions in the order of decreasing value of x. PriorityQueue q = new PriorityQueue<>(new Comparator(){ public int compare(Pair p1, Pair p2){ return Integer.compare(p2.x, p1.x); } }); for(int i = 0; i< N; i++){ for(int j = 0; j< M; j++){ grid[i][j] = ni(); if(grid[i][j]>0){ //inserting into grid all escape positions q.add(new Pair(i*M+j,grid[i][j])); } } } while(!q.isEmpty()){ //Processing nodes in order of their current x value. Pair p = q.poll(); int y = p.ind; int i = y/M,j = y%M, x = p.x-1; survive[i][j] = true; if(x<0)continue; //A position is addedm if it does not move out of grid, is not forbidden and is not already added. if(check(i-1, j, N, M) && !survive[i-1][j] && grid[i-1][j] != -1){ q.add(new Pair(y-M, x)); survive[i-1][j] = true; } if(check(i, j-1, N, M) && !survive[i][j-1] && grid[i][j-1] != -1){ q.add(new Pair(y-1, x)); survive[i][j-1] = true; } if(check(i+1, j, N, M) && !survive[i+1][j] && grid[i+1][j] != -1){ q.add(new Pair(y+M, x)); survive[i+1][j] = true; } if(check(i, j+1, N, M) && !survive[i][j+1] && grid[i][j+1] != -1){ q.add(new Pair(y+1, x)); survive[i][j+1] = true; } } //Printing output for(int i = 0; i< N; i++){ for(int j = 0; j< M; j++){ if(grid[i][j] == -1)out.append("B"); else if(survive[i][j])out.append("Y"); else out.append("N"); } out.append("\n"); } } p(out.toString()); } static boolean check(int i, int j, int N, int M){ return (i>=0 && i=0 && j