#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cctype>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <sstream>
#include <deque>

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

using namespace std;

char m[5][5];
string boards[10];
int cnt = 0;

bool equal(int form, int forinp, bool flg){
    if(flg) {
        REP(i, 5) if (m[form][i] == boards[forinp][5-i-1]) return false;
    } else {
        REP(i, 5) if (m[form][i] == boards[forinp][i]) return false;
    }
    return true;
}

bool check(bool *used){
    bool cpused[10];
    int val[5];
    REP(i, 10) cpused[i] = used[i];
    REP(i, 5) {
        bool flg = 0;

        REP(j, 10) {
            if(cpused[j]) continue;
            if(equal(i, j, false) || equal(i, j, true)) {
                cpused[j] = true;
                flg = true;
                val[i] = j;
                break;
            }
        }
        if (!flg) return false;
    }

    return true;
}


int bt(bool *used,int now){
    if (now == 5){
        if (check(used)) cnt++;
        return cnt;
    }

    for(int i=0;i<10;i++){
        if (used[i] == true) continue;
        used[i] = true;
        REP(j, 5) m[j][now] = boards[i][j];
        bt(used, now+1);

        if ( boards[i][0] == boards[i][4] && boards[i][1] == boards[i][3]){
            used[i]=false;
            continue;
        }

        REP(j, 5) m[j][now] = boards[i][5-j-1];
        bt(used, now+1);
        used[i] = false;
    }
    return cnt;
}


int main(){
    while(cin>>boards[0] && boards[0][0] != 'E'){
        for(int i = 1; i < 10; i++) cin >> boards[i];

        cnt = 0;
        bool used[10]={0};

        //cout << cnt << " " << cnt %8 << endl;
        cout << bt(used, 0)/8 << endl;
    }
    return 0;
}