#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define SIZE 10

enum Type{
	TOP,
	EAST,
	WEST,
	NORTH,
	SOUTH,
	BOTTOM,
};

int N;
int code_index,code_table[65536][6];
int order_index,work_order[6],order_table[120][6];
bool used[6];
char input[6*SIZE][SIZE],base_table[6][SIZE][SIZE];
char TMP[120][6][8][SIZE][SIZE];
Type type_array[6] = {TOP,EAST,WEST,NORTH,SOUTH,BOTTOM};


void roll_90(char table[SIZE][SIZE]){

	char tmp[SIZE][SIZE];

	for(int row = 0; row < N; row++){
		for(int col = 0; col < N; col++){
			tmp[col][N-1-row] = table[row][col];
		}
	}

	for(int row = 0; row < N; row++){
		for(int col = 0; col < N; col++){
			table[row][col] = tmp[row][col];
		}
	}
}

void reverse_table(char table[SIZE][SIZE]){

	char tmp[SIZE][SIZE];

	for(int row = 0; row < N; row++){
		for(int col = 0; col < N; col++){
			tmp[row][col] = table[row][N-1-col];
		}
	}

	for(int row = 0; row < N; row++){
		for(int col = 0; col < N; col++){
			table[row][col] = tmp[row][col];
		}
	}
}

void func(){

	bool FLG = true; //中央部に欠損があるか否か
	int count = 0;

	for(int row = 0; row < 6*N; row++){
		scanf("%s",input[row]);
	}

	for(int i = 0; i < 6; i++){
		for(int row = 0; row < N; row++){
			for(int col = 0; col < N; col++){

				base_table[i][row][col] = input[N*i+row][col];

				if(base_table[i][row][col] == 'X'){
					count++;
				}else{

					if(row >= 1 && row <= N-2 && col >= 1 && col <= N-2){

						FLG = false;
					}
				}
			}
		}
	}


	if(FLG == false || count != 6*N*N-12*N+8){

		printf("No\n");
		return;
	}

	//先に回転させたテーブルを作っておく
	for(int loop = 0; loop < order_index; loop++){
		for(int i = 0; i < 6; i++){
			for(int num = 0; num <= 7; num++){

				for(int row = 0; row < N; row++){
					for(int col = 0; col < N; col++){
						TMP[loop][i][num][row][col] = base_table[order_table[loop][i]][row][col];
					}
				}

				for(int a = 0; a <= num; a++){
					if(a == 4){
						reverse_table(TMP[loop][i][num]);
						continue;
					}
					roll_90(TMP[loop][i][num]);
				}
			}
		}
	}


	//TOPはbase_table[0]で固定
	for(int loop = 0; loop < order_index; loop++){

		for(int i = 0; i < code_index; i++){

			FLG = true;

			//TOPの右辺
			for(int k = 1; k <= N-2; k++){
				if(TMP[loop][TOP][code_table[i][TOP]][k][N-1] == '.' && TMP[loop][EAST][code_table[i][EAST]][0][N-1-k] == '.'){
					FLG = false;
					break;
				}
			}
			if(!FLG)continue;

			//TOPの左辺
			for(int k = 1; k <= N-2; k++){
				if(TMP[loop][TOP][code_table[i][TOP]][k][0] == '.' && TMP[loop][WEST][code_table[i][WEST]][0][k] == '.'){
					FLG = false;
					break;
				}
			}
			if(!FLG)continue;

			//TOPの上辺
			for(int k = 1; k <= N-2; k++){
				if(TMP[loop][TOP][code_table[i][TOP]][0][k] == '.' && TMP[loop][NORTH][code_table[i][NORTH]][0][N-1-k] == '.'){

					FLG = false;
					break;
				}
			}
			if(!FLG)continue;

			//EASTとNORTHの共通辺
			for(int k = 1; k <= N-2; k++){
				if(TMP[loop][EAST][code_table[i][EAST]][k][N-1] == '.' && TMP[loop][NORTH][code_table[i][NORTH]][k][0] == '.'){
					FLG = false;
					break;
				}
			}
			if(!FLG)continue;

			//WESTとNORTHの共通辺
			for(int k = 1; k <= N-2; k++){
				if(TMP[loop][WEST][code_table[i][WEST]][k][0] == '.' && TMP[loop][NORTH][code_table[i][NORTH]][k][N-1] == '.'){
					FLG = false;
					break;
				}
			}
			if(!FLG)continue;

			//TOP右上角
			if(TMP[loop][TOP][code_table[i][TOP]][0][N-1] == '.' && TMP[loop][EAST][code_table[i][EAST]][0][N-1] == '.' &&
					TMP[loop][NORTH][code_table[i][NORTH]][0][0] == '.'){
				continue;
			}
			//TOP左上角
			if(TMP[loop][TOP][code_table[i][TOP]][0][0] == '.' && TMP[loop][WEST][code_table[i][WEST]][0][0] == '.' &&
					TMP[loop][NORTH][code_table[i][NORTH]][0][N-1] == '.'){
				continue;
			}

			//TOPの下辺
			for(int k = 1; k <= N-2; k++){
				if(TMP[loop][TOP][code_table[i][TOP]][N-1][k] == '.' && TMP[loop][SOUTH][code_table[i][SOUTH]][0][k] == '.'){

					FLG = false;
					break;
				}
			}
			if(!FLG)continue;

			//EASTとSOUTHの共通辺
			for(int k = 1; k <= N-2; k++){
				if(TMP[loop][EAST][code_table[i][EAST]][k][0] == '.' && TMP[loop][SOUTH][code_table[i][SOUTH]][k][N-1] == '.'){
					FLG = false;
					break;
				}
			}
			if(!FLG)continue;

			//WESTとSOUTHの共通辺
			for(int k = 1; k <= N-2; k++){
				if(TMP[loop][WEST][code_table[i][WEST]][k][N-1] == '.' && TMP[loop][SOUTH][code_table[i][SOUTH]][k][0] == '.'){
					FLG = false;
					break;
				}
			}
			if(!FLG)continue;

			//TOP右下角
			if(TMP[loop][TOP][code_table[i][TOP]][N-1][N-1] == '.' && TMP[loop][EAST][code_table[i][EAST]][0][0] == '.' &&
					TMP[loop][SOUTH][code_table[i][SOUTH]][0][N-1] == '.'){
				continue;
			}
			//TOP左下角
			if(TMP[loop][TOP][code_table[i][TOP]][N-1][0] == '.' && TMP[loop][WEST][code_table[i][WEST]][0][N-1] == '.' &&
					TMP[loop][SOUTH][code_table[i][SOUTH]][0][0] == '.'){
				continue;
			}

			//EASTとの共通辺
			for(int k = 1; k <= N-2; k++){
				if(TMP[loop][EAST][code_table[i][EAST]][N-1][k] == '.' && TMP[loop][BOTTOM][code_table[i][BOTTOM]][N-1-k][0] == '.'){
					FLG = false;
					break;
				}
			}
			if(!FLG)continue;

			//WESTとの共通辺
			for(int k = 1; k <= N-2; k++){
				if(TMP[loop][WEST][code_table[i][WEST]][N-1][k] == '.' && TMP[loop][BOTTOM][code_table[i][BOTTOM]][k][N-1] == '.'){
					FLG = false;
					break;
				}
			}
			if(!FLG)continue;

			//NORTHとの共通辺
			for(int k = 1; k <= N-2; k++){
				if(TMP[loop][NORTH][code_table[i][NORTH]][N-1][k] == '.' && TMP[loop][BOTTOM][code_table[i][BOTTOM]][0][k] == '.'){
					FLG = false;
					break;
				}
			}
			if(!FLG)continue;

			//SOUTHとの共通辺
			for(int k = 1; k <= N-2; k++){
				if(TMP[loop][SOUTH][code_table[i][SOUTH]][N-1][k] == '.' && TMP[loop][BOTTOM][code_table[i][BOTTOM]][N-1][N-1-k] == '.'){
					FLG = false;
					break;
				}
			}
			if(!FLG)continue;

			//BOTTOM右上角
			if(TMP[loop][BOTTOM][code_table[i][BOTTOM]][0][N-1] == '.' && TMP[loop][NORTH][code_table[i][NORTH]][N-1][N-1] == '.' &&
					TMP[loop][WEST][code_table[i][WEST]][N-1][0] == '.'){
				continue;
			}
			//BOTTOM左上角
			if(TMP[loop][BOTTOM][code_table[i][BOTTOM]][0][0] == '.' && TMP[loop][NORTH][code_table[i][NORTH]][N-1][0] == '.' &&
					TMP[loop][EAST][code_table[i][EAST]][N-1][N-1] == '.'){
				continue;
			}
			//BOTTOM右下角
			if(TMP[loop][BOTTOM][code_table[i][BOTTOM]][N-1][N-1] == '.' && TMP[loop][SOUTH][code_table[i][SOUTH]][N-1][0] == '.' &&
					TMP[loop][WEST][code_table[i][WEST]][N-1][N-1] == '.'){
				continue;
			}
			//BOTTOM左下角
			if(TMP[loop][BOTTOM][code_table[i][BOTTOM]][N-1][0] == '.' && TMP[loop][SOUTH][code_table[i][SOUTH]][N-1][N-1] == '.' &&
					TMP[loop][EAST][code_table[i][EAST]][N-1][0] == '.'){
				continue;
			}

			printf("Yes\n");
			return;
		}
	}

	printf("No\n");
}

void make_code(){

	for(int a = 3; a <= 4; a += 1){
		for(int b = 0; b <= 7; b++){
			for(int c = 0; c <= 7; c++){
				for(int d = 0; d <= 7; d++){
					for(int e = 0; e <= 7; e++){
						for(int f = 0; f <= 7; f++){

							code_table[code_index][TOP]    = a;
							code_table[code_index][EAST]   = b;
							code_table[code_index][WEST]   = c;
							code_table[code_index][NORTH]  = d;
							code_table[code_index][SOUTH]  = e;
							code_table[code_index][BOTTOM] = f;

							code_index++;
						}
					}
				}
			}
		}
	}
}

void make_order(int index){

	if(index == 6){

		for(int i = 0; i < 6; i++){

			order_table[order_index][i] = work_order[i];
		}
		order_index++;
		return;
	}

	for(int i = 1; i <= 5; i++){
		if(used[i])continue;
		used[i] = true;
		work_order[index] = i;
		make_order(index+1);
		used[i] = false;
	}
}

int main(){

	code_index = 0;
	make_code();

	order_index = 0;
	used[0] = true;
	work_order[0] = 0;
	for(int i = 1; i <= 5; i++){
		used[i] = false;
	}
	make_order(1);

	while(true){

		scanf("%d",&N);
		if(N == 0)break;

		func();
	}

	return 0;
}



Measured memory_bytes: 5204