// Arup Guha
// 8/3/2026
// Solution to 1990 UCF HS Programming Contest Problem: Bingo!

/*** Though this isn't stated in the specification, I will ONLY make data
     where all the numbers on the card are unique and all called numbers
	 are unique. These are both true in real bingo. (Callers pull numbers
	 from a bin and put them in a used bucket...and cards with duplicate
	 numbers would be an unfair advantage, more than likely.)
***/

import java.util.*;

public class bingo {
	
	public static void main(String[] args) {
	
		Scanner stdin = new Scanner(System.in);	
		while (stdin.hasNext()) {
		
			// Get the board.
			int[][] vals = new int[5][5];
			for (int i=0; i<5; i++) {
			
				// Annoying.
				int length = (i==2) ? 4 : 5;
			
				// Yes, also annoying...
				for (int j=0; j<length; j++) {
					if (i==2 && j>1)
						vals[i][j+1] = stdin.nextInt();
					else
						vals[i][j] = stdin.nextInt();
				}
			}
			
			// Just get the whole call list.
			ArrayList<String> callList = new ArrayList<String>();
			String x = stdin.next();
			while (!x.equals("0")) {
				callList.add(x);
				x = stdin.next();
			}
			
			// Create my bingo card object!
			card mine = new card(vals);
			
			// Simulate.
			boolean win = false;
			for (int i=0; i<callList.size(); i++) {
			
				// Add it!
				int code = mine.add(callList.get(i));
				
				// We won! - bunch of stuff to do.
				if (code != -1) {
					win = true;
					System.out.println("BINGO! after "+(i+1)+" calls");
					mine.output(code);
					System.out.println();
					break;
				}
			}
			
			// So sad.
			if (!win) {
				System.out.println("No Bingo.");
				System.out.println();
			}
		}
	}
}

class card {

	public String[][] board;
	public HashSet<String> called;
	public HashMap<String,Integer> posMap;
	public int[] rCount;
	public int[] cCount;
	public int fDiag;
	public int bDiag;
	
	// values is 5 by 5, center value is ignored.
	public card(int[][] values) {
	
		// Sorry I am hard-coding.
		board = new String[5][5];
		
		// To speed things along.
		posMap = new HashMap<String,Integer>();
		called = new HashSet<String>();
		
		rCount = new int[5];
		cCount = new int[5];
		
		// Four directions that the middle square hits.
		rCount[2] = 1;
		cCount[2] = 1;
		fDiag = 1;
		bDiag = 1;
		
		// Go through the whole board.
		for (int i=0; i<5; i++) {
			for (int j=0; j<5; j++) {
			
				// Middle Square.
				if (i==2 && j==2)
					board[i][j] = "Free Space";
				
				// Usual.
				else 
					board[i][j] = ""+values[i][j];
				
				// I store my (x,y) as 5*x+y.
				posMap.put(board[i][j], 5*i+j);
			}
		}
	}
	
	// Can only call this method when the game isn't over.
	// Returns -1 if game not over, returns 0-4 if row win, 5-9 if col win
	// 10 for fDiag, 11 for bDiag.
	public int add(String curNum) {
	
		// Not on my board.
		if (!posMap.containsKey(curNum)) return -1;
		
		// This was called before, so no change on my board.
		// I don't do this in my data, but it was easy enough to add.
		if (called.contains(curNum)) return -1;
		
		// Update that this is called.
		called.add(curNum);
		
		// Extract row and column on board.
		int location = posMap.get(curNum);
		int row = location/5;
		int col = location%5;
		
		// Update this row.
		rCount[row]++;
		if (rCount[row] == 5) return row;
		
		// Update this column.
		cCount[col]++;
		if (cCount[col] == 5) return col+5;
		
		// If necessary, the forward diagonal.
		if (row == col) fDiag++;
		if (fDiag == 5) return 10;
		
		// And finally the backward diagonal.
		if (row+col == 4) bDiag++;
		if (bDiag == 5) return 11;
		
		// If we get here, there's no win.
		return -1;
	}
	
	// Must be called with 0 to 11...
	public void output(int code) {
		
		// row win.
		if (code < 5) {
		
			// Doing space separated.
			for (int i=0; i<4; i++)
				System.out.print(board[code][i]+" ");
			System.out.println(board[code][4]);
			
		}
		
		// col win.
		else if (code < 10) {

			// Same here, notice the -5...
			for (int i=0; i<4; i++)
				System.out.print(board[i][code-5]+" ");
			System.out.println(board[4][code-5]);
			
		}
		
		// Forward diag.
		else if (code == 10) {
		
			// Just hard-coded.
			for (int i=0; i<4; i++)
				System.out.print(board[i][i]+" ");
			System.out.println(board[4][4]);
			
		}
		
		// Back diag.
		else {

			// Just hard-coded.
			for (int i=0; i<4; i++)
				System.out.print(board[i][4-i]+" ");
			System.out.println(board[4][0]);
			
		}
	
	}
}