#include"bits/stdc++.h"

using namespace std;

#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,m,n) for(int i=(m);i<(n);i++)

const bool DEBUG = false;

struct piece {
	int cell[10][10][2][4];//x,y,reversed,dir
	bool reversed;//01
	int dir;//0123
	piece() :reversed(0), dir(0) {}
};
int pos[5];
int N;
int cnt[10][10][10];//x,y,z
piece pieces[6];
struct Cube {
	int cnt[10][10][10];

	Cube(){
        REP(i, N)REP(j, N)REP(k, N)cnt[i][j][k] = 0;
    }

	bool paint0() {
		int id = 0;
		int rev = pieces[id].reversed;
		int dir = 0;
		int z = 0;
		REP(x, N)REP(y, N) {
			cnt[x][y][z] += pieces[id].cell[x][y][rev][dir];
		}
		return true;
	}
	bool paint(int id) {
		int rev = pieces[id].reversed;
		int dir = pieces[id].dir;
		if (pos[id - 1] == 0) {
			int z = N - 1;
			REP(x, N)REP(y, N) {
				cnt[x][y][z] += pieces[id].cell[x][y][rev][dir];
				if (cnt[x][y][z] > 1)return false;
			}
		}
		else if (pos[id - 1] == 1) {
			int y = N - 1;
			REP(x, N)REP(z, N) {
				cnt[x][y][z] += pieces[id].cell[x][z][rev][dir];
				if (cnt[x][y][z] > 1)return false;
			}
		}
		else if (pos[id - 1] == 2) {
			int y = 0;
			REP(x, N)REP(z, N) {
				cnt[x][y][z] += pieces[id].cell[x][z][rev][dir];
				if (cnt[x][y][z] > 1)return false;
			}
		}
		else if (pos[id - 1] == 3) {
			int x = 0;
			REP(y, N)REP(z, N) {
				cnt[x][y][z] += pieces[id].cell[z][y][rev][dir];
				if (cnt[x][y][z] > 1)return false;
			}
		}
		else if (pos[id - 1] == 4) {
			int x = N - 1;
			REP(y, N)REP(z, N) {
				cnt[x][y][z] += pieces[id].cell[z][y][rev][dir];
				if (cnt[x][y][z] > 1)return false;
			}
		}
		return true;
	}
	bool canConstruct() {
		//cerr << "check" << endl;
		int x = 0;
		REP(y, N)REP(z, N) {
			if (cnt[x][y][z] != 1)return false;
		}
		x = N - 1;
		REP(y, N)REP(z, N) {
			if (cnt[x][y][z] != 1)return false;
		}

		int y = 0;
		REP(x, N)REP(z, N) {
			if (cnt[x][y][z] != 1)return false;
		}
		y = N - 1;
		REP(x, N)REP(z, N) {
			if (cnt[x][y][z] != 1)return false;
		}

		int z = 0;
		REP(y, N)REP(x, N) {
			if (cnt[x][y][z] != 1)return false;
		}
		z = N - 1;
		REP(y, N)REP(x, N) {
			if (cnt[x][y][z] != 1)return false;
		}
		return true;
	}
};

void show(int angle) {
	bool ok = true;
	if (angle == 0) {
		int z = 0;
		REP(x, N) {
			REP(y, N) {
				cout << cnt[x][y][z];
				if (cnt[x][y][z] != 1)ok = false;
			}cout << endl;
		}
	}
	else if (angle == 1) {
		int z = N - 1;
		REP(x, N) {
			REP(y, N) {
				cout << cnt[x][y][z];
				if (cnt[x][y][z] != 1)ok = false;
			}cout << endl;
		}
	}
	else if (angle == 2) {
		int x = 0;
		REP(y, N) {
			REP(z, N) {
				cout << cnt[x][y][z];
				if (cnt[x][y][z] != 1)ok = false;
			}cout << endl;
		}
	}
	else if (angle == 3) {
		int x = N - 1;
		REP(y, N) {
			REP(z, N) {
				cout << cnt[x][y][z];
				if (cnt[x][y][z] != 1)ok = false;
			}cout << endl;
		}
	}
	else if (angle == 4) {
		int y = 0;
		REP(x, N) {
			REP(z, N) {
				cout << cnt[x][y][z];
				if (cnt[x][y][z] != 1)ok = false;
			}cout << endl;
		}
	}
	else if (angle == 5) {
		int y = N - 1;
		REP(x, N) {
			REP(z, N) {
				cout << cnt[x][y][z];
				if (cnt[x][y][z] != 1)ok = false;
			}cout << endl;
		}
	}
	if (ok) {
		cout << "ok!!!!!!!!!" << endl;
	}
}


clock_t start;
clock_t end_t;
void solve() {

	cin >> N;
	if (N == 0) {
		end_t = clock();
		double TIME = static_cast<double>(end_t - start) / CLOCKS_PER_SEC;
		//cerr << "elapsed time:" << TIME << "[sec]" << endl;
		exit(0);
	}
	REP(i, 6) {
		pieces[i].reversed = false;
		REP(x, N)REP(y, N)REP(rev, 2)REP(dir, 4) {
			pieces[i].cell[x][y][rev][dir] = 0;
			pieces[i].dir = 0;
		}
	}
	REP(i, 6) {
		REP(x, N) {
			REP(y, N) {
				char c; cin >> c;
				if (c == 'X') {
					pieces[i].cell[x][y][0][0] = 1;
					pieces[i].cell[N - 1 - x][y][1][0] = 1;
				}
				else {
					pieces[i].cell[x][y][0][0] = 0;
					pieces[i].cell[N - 1 - x][y][1][0] = 0;
				}
			}
		}
		FOR(dir, 1, 4) REP(rev, 2)REP(x, N)REP(y, N) {
			pieces[i].cell[y][N - 1 - x][rev][dir] = pieces[i].cell[x][y][rev][dir - 1];
		}
		if (DEBUG) {
			REP(dir, 4) {
				cout << "dir:" << dir << endl;
				REP(x, N) {
					REP(y, N) {
						cout << pieces[i].cell[x][y][0][dir];
					}cout << endl;
				}
				cout << endl;
			}
		}
	}

	REP(i, 5)pos[i] = i;
	do {
		REP(rev0, 2) {
			Cube cube0;
			pieces[0].reversed = rev0;
			pieces[0].dir = 0;
			cube0.paint0();
			REP(rev1, 2)REP(dir1, 4) {
				Cube cube1 = cube0;
				pieces[1].reversed = rev1;
				pieces[1].dir = dir1;
				if (!cube1.paint(1)) {
					//cerr << "failed on 1" << endl;
					continue;
				}
				else {
					//cerr << "succeeded on 1" << endl;
				}
				REP(rev2, 2)REP(dir2, 4) {
					pieces[2].reversed = rev2;
					pieces[2].dir = dir2;
					Cube cube2 = cube1;
					if (!cube2.paint(2))continue;
					REP(rev3, 2)REP(dir3, 4) {
						pieces[3].reversed = rev3;
						pieces[3].dir = dir3;
						Cube cube3 = cube2;
						if (!cube3.paint(3))continue;
						REP(rev4, 2)REP(dir4, 4) {
							pieces[4].reversed = rev4;
							pieces[4].dir = dir4;
							Cube cube4 = cube3;
							if (!cube4.paint(4))continue;
							REP(rev5, 2)REP(dir5, 4) {
								pieces[5].reversed = rev5;
								pieces[5].dir = dir5;
								Cube cube5 = cube4;
								if (!cube5.paint(5))continue;
								if (cube5.canConstruct()) {
									cout << "Yes" << endl;
									return;
								}
							}
						}
					}
				}
			}
		}
	} while (next_permutation(pos, pos + 5));
	cout << "No" << endl;
}
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	start = clock();
	while (true)solve();
}


Measured memory_bytes: 3236