// Arup Guha
// 3/9/2020
// Solution to 2020 UCF HS Contest Problem: Blockdoku

import java.util.*;

public class block {

	final public static int N = 9;
	final public static int BOX = 3;
	final public static int NUMBLOCKS = 3;
	
	public static boolean[][] grid;
	public static boolean[][][] pieces;
	public static int[][] dims;
	
	public static void main(String[] args) {
	
		Scanner stdin = new Scanner(System.in);
		int nC = stdin.nextInt();
		
		// Process each case.
		for (int loop=0; loop<nC; loop++) {
		
			// Read grid, set to true if something can be placed there.
			grid = new boolean[N][N];
			for (int i=0; i<N; i++) {
				char[] line = stdin.next().toCharArray();
				for (int j=0; j<N; j++)
					grid[i][j] = line[j] == '.';
			}
			
			// Read in the pieces.
			dims = new int[NUMBLOCKS][2];
			pieces = new boolean[NUMBLOCKS][][];
			
			for (int i=0; i<NUMBLOCKS; i++) {
			
				// Get the dimensions.
				dims[i][0] = stdin.nextInt();
				dims[i][1] = stdin.nextInt();
				
				// Set up the piece.
				pieces[i] = new boolean[dims[i][0]][dims[i][1]];
				for (int j=0; j<dims[i][0]; j++) {
					char[] line = stdin.next().toCharArray();
					for (int k=0; k<dims[i][1]; k++)
						pieces[i][j][k] = line[k] == '.';
				}
			}
			
			// Ta da!
			System.out.println(go(0));
		}
	}
	
	// Returns the result of recursively placing piece k somewhere given the current formation.
	public static String go(int k) {
	
		// Allows us to place fewer than 3 blocks.
		if (isValid()) return "Yes";
		
		// No more blocks to place...
		if (k == NUMBLOCKS) return "No";
		
		// Try placing this piece in all 81 places.
		for (int i=0; i<N; i++) {
			for (int j=0; j<N; j++) {
				
				// See if this fits in corner (i, j).
				if (canPlace(k,i,j)) {
					
					// Put it down.
					place(k,i,j);
					
					// Recurse.
					String tmp = go(k+1);
					
					// This worked!
					if (tmp.equals("Yes")) return "Yes";
					
					// Undo the piece.
					unplace(k,i,j);
				}
			}
		}
		
		// If we get here, our last option is to just move onto piece k+1 without placing k.
		return go(k+1);
	}
	
	// Returns true iff this is a valid ending state.
	public static boolean isValid() {
		
		// See if any row is all filled in.
		for (int i=0; i<N; i++) 
			if (isValidRow(i))
				return true;
			
		// Or column.
		for (int i=0; i<N; i++)
			if (isValidCol(i))
				return true;
			
		// Or box.
		for (int i=0; i<N; i++)
			if (isValidBox(i/BOX, i%BOX))
				return true;
			
		// Nothing worked.
		return false;
	}
	
	// Returns true iff everything on row i is false.
	public static boolean isValidRow(int i) {
		for (int j=0; j<N; j++)
			if (grid[i][j])
				return false;
		return true;
	}
	
	// Returns true iff everything on col j is false.
	public static boolean isValidCol(int j) {
		for (int i=0; i<N; i++)
			if (grid[i][j])
				return false;
		return true;
	}
	
	// Returns true iff everything in box (x,y), which has top left corner (BOX*x, BOX*y) and dimensions
	// BOX by BOX is all false.
	public static boolean isValidBox(int x, int y) {
		for (int i=BOX*x; i<BOX*x+BOX; i++)
			for (int j=BOX*y; j<BOX*y+BOX; j++)
				if (grid[i][j])
					return false;
		return true;
	}
	
	// Returns true iff you can place piece number piece with top left at (x, y).
	public static boolean canPlace(int piece, int x, int y) {
		
		// Do each square 
		for (int i=x; i<x+dims[piece][0]; i++) {
			for (int j=y; j<y+dims[piece][1]; j++) {
				
				// Doesn't matter.
				if (pieces[piece][i-x][j-y]) continue;
				
				// Definitely can't do it - out of bounds.
				if (!inbounds(i, j)) return false;

				// Square is taken, can't do it.
				if (!grid[i][j]) return false;
			}
		}
		
		// Good if we get here.
		return true;
	}
	
	// Places piece number piece with top left at (x, y).
	public static void place(int piece, int x, int y) {
		
		// Do each square 
		for (int i=x; i<x+dims[piece][0]; i++) {
			for (int j=y; j<y+dims[piece][1]; j++) {
				
				// Doesn't matter.
				if (pieces[piece][i-x][j-y]) continue;
				
				// Set it!!!
				grid[i][j] = false;
			}
		}
	}	
	
	// Unplaces piece number piece with top left at (x, y).
	public static void unplace(int piece, int x, int y) {
		
		// Do each square 
		for (int i=x; i<x+dims[piece][0]; i++) {
			for (int j=y; j<y+dims[piece][1]; j++) {
				
				// Doesn't matter.
				if (pieces[piece][i-x][j-y]) continue;
				
				// Set it back!!!
				grid[i][j] = true;
			}
		}
	}	
	
	// Returns true iff (x,y) is inbounds.
	public static boolean inbounds(int x, int y) {
		return x >= 0 && x < N && y >= 0 && y < N;
	}
}