import java.util.*; public class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); int T = sc.nextInt(); for(int t = 0; t < T; t++){ long M = sc.nextLong(); System.out.println(40); char[][] ans = new char[40][40]; for(int i = 0;i < 40;i++){ for(int j = 0;j < 40; j++){ ans[i][j] = (i < 39 && j < 39) ? '#' : '.'; } } for(int i = 0;i < 18;i++){ for(int a = 0; a < (i%2==0 ? 2 : 3); a++){ for(int b = 0; b < (i%2==0 ? 3 : 2); b++){ ans[i * 2 + a][i * 2 + b] = '.'; } } if(M % 3 > 0){ for(int j = i * 2; j < 40; j++){ ans[i * 2][j] = '.'; } } if(M % 3 > 1){ for(int j = i * 2; j < 40; j++){ ans[j][i * 2] = '.'; } } M /= 3; } if(M > 0){ ans[36][36] = '.'; ans[36][37] = '.'; ans[36][38] = '.'; } if(M > 1){ ans[37][36] = '.'; ans[38][36] = '.'; } ans[0][1] = 'P'; ans[1][0] = 'P'; StringBuilder sb = new StringBuilder(); for(int i = 0;i < 40;i++){ for(int j = 0;j < 40; j++){ sb.append(ans[i][j]); } sb.append("\n"); } System.out.println(sb.toString()); } } }