// Patrick Fenelon
// 7/14/2011
// Solution for BHCSI 2011 Practice Contest #1 Problem: Connect Four
import java.io.*;
import java.util.*;

public class game {
	
	public static void main(String[] args) throws IOException{
		//initalize the file reader
		Scanner sc = new Scanner(new File("game.in"));
		//call the function that does the program
		new game(sc);
	}
	
	public game(Scanner sc){
		//read in the number of test cases
		int numberOfTestCases = sc.nextInt();

		//iterate over the test cases
		for(int testCase = 0; testCase < numberOfTestCases; testCase++){

			//declare the grid that will be printed out later
			char[][] grid = new char[6][7];

			//declare an array that will keep track of the lowest open square
			int[] top = new int[7];

			//initalize the grid to blanks
			for(int i = 0; i < 7; i++){
				for(int j = 0; j < 6; j++){
					grid[j][i] = '_';
				}
			}

			//initalize tracking array
			for(int i = 0; i < 7; i++){
				//the top open cell is cell 5
				top[i] = 5;
			}

			//game starts with Cottontail
			char player = 'C';

			//read in the number of moves
			int numberOfMoves = sc.nextInt();

			//iterate over the moves
			for(int move = 0; move < numberOfMoves; move++){

				//read in the string representing the move
				String binarySeq = sc.next();

				//translate it into 0-based array notation
				int col = getCol(binarySeq);

				//get the row to move in
				int row = top[col];

				//decrement the tracking array, remember up is negative
				top[col]--;

				//place the peice
				grid[row][col] = player;

				//swap out the players
				if(player == 'C')
					player = 'P';
				else
					player = 'C';
			}

			//print out the array
			for(int i = 0; i < 6; i++){
				for(int j = 0; j < 7; j++){
					System.out.print(grid[i][j]);
				}
				System.out.println();
			}
			System.out.println();
		}
	}

	//method returns the column number from the string
	public int getCol(String s){
		int ret = 0;
		//the first place is the 4th digit
		if(s.charAt(0) == '|')
			ret += 4;	//add 4 if it is a one
		//the second place is the 2nd digit
		if(s.charAt(1) == '|')
			ret += 2;	//add 2 if it is a one
		//the first place is the 1st digit
		if(s.charAt(2) == '|')
			ret += 1;	//add 1 if it is a one
		return ret-1;	//subtract 1 from the number to translate to a 0-based array
	}
}
