#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e3 + 5;
const int inf = 0x3f3f3f3f;
int n, bs;
char a[10][15][15], b[10][15][15];
int id[10];
void rotate(int x, int type, int y) {
    int u, v;
    if(type == 0) {
        for(int i = 0; i < n; ++i) {
            // b[x][u][v] = a[y][u][v];
            u = i, v = 0;
            b[x][u][v] = a[y][u][v];
            u = i, v = n - 1;
            b[x][u][v] = a[y][u][v];
            u = 0, v = i;
            b[x][u][v] = a[y][u][v];
            u = n - 1, v = i;
            b[x][u][v] = a[y][u][v];
        }
    } else if(type == 1) {
        for(int i = 0; i < n; ++i) {
            // b[x][u][v] = a[y][u][n - v - 1];
            u = i, v = 0;
            b[x][u][v] = a[y][u][n - v - 1];
            u = i, v = n - 1;
            b[x][u][v] = a[y][u][n - v - 1];
            u = 0, v = i;
            b[x][u][v] = a[y][u][n - v - 1];
            u = n - 1, v = i;
            b[x][u][v] = a[y][u][n - v - 1];
        }
    } else if(type == 2) {
        for(int i = 0; i < n; ++i) {
            // b[x][u][v] = a[y][n - u - 1][v];
            u = i, v = 0;
            b[x][u][v] = a[y][n - u - 1][v];
            u = i, v = n - 1;
            b[x][u][v] = a[y][n - u - 1][v];
            u = 0, v = i;
            b[x][u][v] = a[y][n - u - 1][v];
            u = n - 1, v = i;
            b[x][u][v] = a[y][n - u - 1][v];
        }
    } else if(type == 3) {
        for(int i = 0; i < n; ++i) {
            // b[x][u][v] = a[y][n - u - 1][n - v - 1];
            u = i, v = 0;
            b[x][u][v] = a[y][n - u - 1][n - v - 1];
            u = i, v = n - 1;
            b[x][u][v] = a[y][n - u - 1][n - v - 1];
            u = 0, v = i;
            b[x][u][v] = a[y][n - u - 1][n - v - 1];
            u = n - 1, v = i;
            b[x][u][v] = a[y][n - u - 1][n - v - 1];
        }
    } else if(type == 4) {
        for(int i = 0; i < n; ++i) {
            // b[x][u][v] = a[y][v][u];
            u = i, v = 0;
            b[x][u][v] = a[y][v][u];
            u = i, v = n - 1;
            b[x][u][v] = a[y][v][u];
            u = 0, v = i;
            b[x][u][v] = a[y][v][u];
            u = n - 1, v = i;
            b[x][u][v] = a[y][v][u];
        }
    } else if(type == 5) {
        for(int i = 0; i < n; ++i) {
            // b[x][u][v] = a[y][v][n - u - 1];
            u = i, v = 0;
            b[x][u][v] = a[y][v][n - u - 1];
            u = i, v = n - 1;
            b[x][u][v] = a[y][v][n - u - 1];
            u = 0, v = i;
            b[x][u][v] = a[y][v][n - u - 1];
            u = n - 1, v = i;
            b[x][u][v] = a[y][v][n - u - 1];
        }
    } else if(type == 6) {
        for(int i = 0; i < n; ++i) {
            // b[x][u][v] = a[y][n - v - 1][u];
            u = i, v = 0;
            b[x][u][v] = a[y][n - v - 1][u];
            u = i, v = n - 1;
            b[x][u][v] = a[y][n - v - 1][u];
            u = 0, v = i;
            b[x][u][v] = a[y][n - v - 1][u];
            u = n - 1, v = i;
            b[x][u][v] = a[y][n - v - 1][u];
        }
    } else if(type == 7) {
        for(int i = 0; i < n; ++i) {
            // b[x][u][v] = a[y][n - v - 1][n - u - 1];
            u = i, v = 0;
            b[x][u][v] = a[y][n - v - 1][n - u - 1];
            u = i, v = n - 1;
            b[x][u][v] = a[y][n - v - 1][n - u - 1];
            u = 0, v = i;
            b[x][u][v] = a[y][n - v - 1][n - u - 1];
            u = n - 1, v = i;
            b[x][u][v] = a[y][n - v - 1][n - u - 1];
        }
    }
}
bool vertex2() {
    int cnt = 0;
    if(b[0][0][0] == 'X') ++cnt;
    if(b[1][n - 1][0] == 'X') ++cnt;
    if(b[2][0][n - 1] == 'X') ++cnt;
    if(cnt != 1) return false;
    return true;
}
bool vertex3() {
    int cnt = 0;
    if(b[0][0][n - 1] == 'X') ++cnt;
    if(b[1][n - 1][n - 1] == 'X') ++cnt;
    if(b[3][0][0] == 'X') ++cnt;
    if(cnt != 1) return false;
    return true;
}
bool vertex4() {
    int cnt = 0;
    if(b[0][n - 1][0] == 'X') ++cnt;
    if(b[2][n - 1][n - 1] == 'X') ++cnt;
    if(b[4][0][0] == 'X') ++cnt;
    if(cnt != 1) return false;
    cnt = 0;
    if(b[0][n - 1][n - 1] == 'X') ++cnt;
    if(b[3][n - 1][0] == 'X') ++cnt;
    if(b[4][0][n - 1] == 'X') ++cnt;
    if(cnt != 1) return false;
    return true;
}
bool vertex5() {
    int cnt = 0;
    if(b[5][n - 1][0] == 'X') ++cnt;
    if(b[1][0][0] == 'X') ++cnt;
    if(b[2][0][0] == 'X') ++cnt;
    if(cnt != 1) return false;
    cnt = 0;
    if(b[5][n - 1][n - 1] == 'X') ++cnt;
    if(b[1][0][n - 1] == 'X') ++cnt;
    if(b[3][0][n - 1] == 'X') ++cnt;
    if(cnt != 1) return false;
    cnt = 0;
    if(b[5][0][0] == 'X') ++cnt;
    if(b[2][n - 1][0] == 'X') ++cnt;
    if(b[4][n - 1][0] == 'X') ++cnt;
    if(cnt != 1) return false;
    cnt = 0;
    if(b[5][0][n - 1] == 'X') ++cnt;
    if(b[3][n - 1][n - 1] == 'X') ++cnt;
    if(b[4][n - 1][n - 1] == 'X') ++cnt;
    if(cnt != 1) return false;
    return true;
}
bool edge1() {
    for(int i = 1; i < n - 1; ++i) {
        int cnt = 0;
        if(b[0][0][i] == 'X') ++cnt;
        if(b[1][n - 1][i] == 'X') ++cnt;
        if(cnt != 1) return false;
    }
    return true;
}
bool edge2() {
    for(int i = 1; i < n - 1; ++i) {
        int cnt = 0;
        if(b[0][i][0] == 'X') ++cnt;
        if(b[2][i][n - 1] == 'X') ++cnt;
        if(cnt != 1) return false;
    }
    for(int i = 1; i < n - 1; ++i) {
        int cnt = 0;
        if(b[1][i][0] == 'X') ++cnt;
        if(b[2][0][i] == 'X') ++cnt;
        if(cnt != 1) return false;
    }
    return true;
}
bool edge3() {
    for(int i = 1; i < n - 1; ++i) {
        int cnt = 0;
        if(b[0][i][n - 1] == 'X') ++cnt;
        if(b[3][i][0] == 'X') ++cnt;
        if(cnt != 1) return false;
    }
    for(int i = 1; i < n - 1; ++i) {
        int cnt = 0;
        if(b[1][i][n - 1] == 'X') ++cnt;
        if(b[3][0][n - 1 - i] == 'X') ++cnt;
        if(cnt != 1) return false;
    }
    return true;
}
bool edge4() {
    for(int i = 1; i < n - 1; ++i) {
        int cnt = 0;
        if(b[0][n - 1][i] == 'X') ++cnt;
        if(b[4][0][i] == 'X') ++cnt;
        if(cnt != 1) return false;
    }
    for(int i = 1; i < n - 1; ++i) {
        int cnt = 0;
        if(b[2][n - 1][i] == 'X') ++cnt;
        if(b[4][n - 1 - i][0] == 'X') ++cnt;
        if(cnt != 1) return false;
    }
    for(int i = 1; i < n - 1; ++i) {
        int cnt = 0;
        if(b[3][n - 1][i] == 'X') ++cnt;
        if(b[4][i][n - 1] == 'X') ++cnt;
        if(cnt != 1) return false;
    }
    return true;
}
bool edge5() {
    for(int i = 1; i < n - 1; ++i) {
        int cnt = 0;
        if(b[5][n - 1][i] == 'X') ++cnt;
        if(b[1][0][i] == 'X') ++cnt;
        if(cnt != 1) return false;
    }
    for(int i = 1; i < n - 1; ++i) {
        int cnt = 0;
        if(b[5][i][0] == 'X') ++cnt;
        if(b[2][n - 1 - i][0] == 'X') ++cnt;
        if(cnt != 1) return false;
    }
    for(int i = 1; i < n - 1; ++i) {
        int cnt = 0;
        if(b[5][i][n - 1] == 'X') ++cnt;
        if(b[3][n - 1 - i][n - 1] == 'X') ++cnt;
        if(cnt != 1) return false;
    }
    for(int i = 1; i < n - 1; ++i) {
        int cnt = 0;
        if(b[5][0][i] == 'X') ++cnt;
        if(b[4][n - 1][i] == 'X') ++cnt;
        if(cnt != 1) return false;
    }
    return true;
}
bool judge() {
    do {
        for (int i1 = 0; i1 < 8; i1++) {
            rotate(1, i1, id[0]);
            if (!edge1()) continue;
        for (int i2 = 0; i2 < 8; i2++) {
            rotate(2, i2, id[1]);
            if (!edge2()) continue;
            if (!vertex2()) continue;
        for (int i3 = 0; i3 < 8; i3++) {
            rotate(3, i3, id[2]);
            if (!edge3()) continue;
            if (!vertex3()) continue;
        for (int i4 = 0; i4 < 8; i4++) {
            rotate(4, i4, id[3]);
            if (!edge4()) continue;
            if (!vertex4()) continue;
        for (int i5 = 0; i5 < 8; i5++) {
            rotate(5, i5, id[4]);
            if (!edge5()) continue;
            if (!vertex5()) continue;
            return true;
        }}}}}
    } while(next_permutation(id, id + 5));
    return false;
}
int main() {
    while(scanf("%d", &n) != EOF) {
        if(n == 0) break;
        // getchar();
        for(int i = 0; i < 6; ++i) {
            for(int j = 0; j < n; ++j) {
                scanf("%s", a[i][j]);
            }
        }
        for(int i = 0; i < n; ++i) {
            for(int j = 0; j < n; ++j) {
                b[0][i][j] = a[0][i][j];
            }
        }
        bs = 1;
        for(int i = 0; i < 5; ++i) {
            id[i] = i + 1;
            bs = bs*8;
        }
        if(judge()) puts("Yes");
        else puts("No");
    }
    return 0;
}


Measured memory_bytes: 3160