public static void main( String[ ] args ) throws IOException {
		BufferedReader in = new BufferedReader( new InputStreamReader( System.in ) );
		String line = "";
		StringBuilder out = new StringBuilder( );

		int n = Integer.parseInt( in.readLine( ) );

		for ( int p = 0; p < n; p++ ) {
			int index = 0;
			cube = new char[ 54 ];
			for ( int i = 0; i < 9; i++ ) {
				line = in.readLine( );
				char arr[] = line.toCharArray( );
				for ( int j = 0; j < arr.length; j++ ) {
					if ( arr[ j ] != ' ' )
						cube[ index++ ] = arr[ j ];
				}
			}

			String cad[] = in.readLine( ).split( " " );
			for ( int i = 0; i < cad.length; i++ ) {
				if ( cad[ i ].equals( "0" ) )
					break;
				if ( Integer.parseInt( cad[ i ] ) > 0 ) {
					rotate( cube, Integer.parseInt( cad[ i ] ) - 1, 0 );
				} else {
					rotate( cube, (Integer.parseInt( cad[ i ] ) * -1) - 1, 1 );
				}
			}

			if ( win( ) ) {
				System.out.println( "Yes, grandpa!" );
			} else {
				System.out.println( "No, you are wrong!" );
			}

		}

	}