import java.io.File;
import java.io.PrintStream;
import java.util.Scanner;


public class P5 {
	
	private boolean[][] rotate(boolean[][] piece) {
		boolean[][] p = new boolean[4][4];
		for (int x = 3; x >= 0; x--) {
			for (int y = 0; y < 4; y++) {
				p[x][y] = piece[y][3 - x];
			}
		}
		return p;
	}
	
	private boolean[][] copyPiecetoBoard(boolean[][] piece, boolean[][] board, int dx, int dy) {
		boolean[][] b = new boolean[10][6];
		for (int y = 0; y < 6; y++) {
			for (int x = 0; x < 10; x++) {
				if (board[x][y]) {
					b[x][y] = true;
				}
				
			}
		}
		for (int y= 0; y < 4; y++) {
			for (int x= 0; x < 4; x++) {
				if (piece[x][y]) {
					if (x + dx >= 0 && x + dx < 10 && y + dy >= 0 && y + dy < 6) {
						b[x + dx][y + dy] = true;
					}
				}
			}
		}
		
		return b;
	}
	
	
	
	private boolean collide(boolean[][] piece, boolean[][] board, int dx, int dy) {
		boolean[][] b = new boolean[10][6];
		for (int y = 0; y < 6; y++) {
			for (int x = 0; x < 10; x++) {
				if (board[x][y]) {
					b[x][y] = true;
				}
				
			}
		}
		for (int y= 0; y < 4; y++) {
			for (int x= 0; x < 4; x++) {
				if (piece[x][y]) {
					if (x + dx >= 0 && x + dx < 10 && y + dy >= 0 && y + dy < 6) {
						
						if (b[x + dx][y + dy] == true) {
							return true;
						}
					
						
					}
					else if (!(x + dx >= 0 && x + dx < 10 && y + dy < 6)){
						return true;
					}
					
				}
			}
		}
		
		return false;
	}
	
	private void print(boolean[][] piece, boolean[][] board, int dx, int dy) {
		boolean[][] b = copyPiecetoBoard(piece, board, dx, dy);
		print(b);
	}
	
	private void print(boolean[][] a) {
		for (int y = 0; y < a[0].length; y++) {
			for (int x = 0; x < a.length; x++) {
				if (a[x][y] == true) {
					System.out.print("#");
				}
				else {
					System.out.print(".");
				}
			}
			System.out.println();
		}
		System.out.println();
	}
	
	public void solve(Scanner s) throws Exception {
		PrintStream out = new PrintStream(new File("OUT5.txt"));
		
		for (int i = 0; i < 5; i++) {
			
			//Read in the pieces
			boolean[][] piece = new boolean[4][4];
			for (int y = 0; y < 4; y++) {
				String str = s.next();
				for (int x = 0; x < 4; x++) {
					if (str.charAt(x) == '.') {
						piece[x][y] = false;
					}
					else {
						piece[x][y] = true;
					}
				}
			}
			
			print(piece);
			
			//Read in the board
			boolean[][] board = new boolean[10][6];
			for (int y = 0; y < 6; y++) {
				String str = s.next();
				for (int x = 0; x < 10; x++) {
					board[x][y] = (str.charAt(x) == '#');
				}
			}
			print(board);
			
			//Rotate the piece and attempt to put it in
			int max = 0;
			for (int j = 0; j < 4; j++) {
				System.out.println("ROTATE");
				piece = rotate(piece);
				
				for (int x = -3; x < 6; x++) {
					System.out.println("DROPPING at x: " + x);
					max = Math.max(max, solve(piece, board,x ));
				}
				System.out.println();
				System.out.println();
			}
		
			System.out.println(max);
			out.println(max);
			
			
		}
		out.close();
		
	}
	
	private int solve(boolean[][] piece, boolean[][] board, int x) {
		System.out.println("Solving");
		
		for (int y = -4; y < 6; y++) {
			//print(piece, board, x,y );
			if (collide(piece, board, x, y)) {
				
				boolean[][] b = copyPiecetoBoard(piece, board, x, y - 1);
				
				//Now check how many rows are filled
				int rowsFilled = 0;
				for (int i = 0; i < 6; i++) {
					boolean rowComplete = true;
					for (int j = 0; j < 10; j++) {
						if (!b[j][i]) {
							rowComplete = false;
							
						}
					}
					if (rowComplete) {
						rowsFilled++;
						System.out.println("Row Completed :" + i);
					
					}
				}
				return rowsFilled;
				
			}
			
		}
		return 0;
		
//		//x and y rep the top left corner
//		int maxRows = 0;
//		//Move the piece down
//		for (int y = -4; y < 6; y++) {
//			
//			print(piece	, board, x, y);
//			
//			for (int boardX = 0; boardX < 10; boardX++) {
//				for (int boardY = 0; boardY < 6; boardY++) {
//					
//					for (int pieceX = 0; pieceX < 4; pieceX++) {
//						for (int pieceY =0 ; pieceY <4; pieceY++) {
//							
//							if (piece[pieceX][pieceY] == true) {
//								//Check if pieceX, pieceY collides with board[pieceX + x][pieceY + boardY]
//								if (pieceX + x >= 0 && pieceX + x < 10 && pieceY + y >= 0) {
//									if (pieceY + y >= 5 || board[pieceX + x][pieceY + y]) {
//										
//										//Collision
//										boolean[][] b = new boolean[10][6];
//										for (int f = 0; f < 10; f++) {
//											for (int g = 0; g < 6; g++) {
//												b[f][g] = board[f][g];
//											}
//										}
//										//Alright plug those in
//										for (int i = 0; i < 4; i++) {
//											for (int j = 0 ;j < 4; j++) {
//												
//												if (i + x >= 0 && i + x < 4 && j + y >= 0 && j + y < 4 && piece[i][j]) {
//													b[i + x][j + y] = true;
//												}
//												
//											}
//										}
//										
//										//Now check how many rows are filled
//										int rowsFilled = 0;
//										for (int i = 0; i < 6; i++) {
//											boolean rowComplete = true;
//											for (int j = 0; j < 10; j++) {
//												if (!b[j][i]) {
//													rowComplete = false;
//													continue;
//												}
//											}
//											if (rowComplete) {
//												rowsFilled++;
//												System.out.println("Row Completed :" + i);
//											
//											}
//										}
//										return rowsFilled;
//										
//									}
//								}
//							}
//									
//						}
//					}
//				}
//			}
//			
//		}
//		
//		
//		System.err.println("stuff");
//		return -1;
	}
	
	

	public static void main(String[] args) throws Exception {
		new P5().solve(new Scanner(new File("DATA5.txt")));
	}
}

