#include <bits/stdc++.h>
using namespace std;
string data[10];
string sp[5];
int cnt;
string strrev(string *str) {
  string s = "";
  for (int i = 0; i < str->length(); i++) {
    s += (*str)[str->length() - 1 - i];
  }
  return s;
}
void rec(int flag, int step) {
  if (step == 10) {
    cnt++;
  } else if (step >= 5) {
    for (int i = 0; i < 10; i++) {
      if ((flag & (1 << i)) == 0) {
        for (int t = 0; t < 2; t++) {
          string tmp;
          if (t == 0)
            tmp = data[i];
          else
            tmp = strrev(&data[i]);
          for (int j = 0; j < 5; j++) {
            if (tmp[j] == sp[j][step - 5]) break;
            if (j + 1 == 5) rec(flag | (1 << i), step + 1);
          }
        }
      }
    }
  } else {
    for (int i = 0; i < 10; i++) {
      if ((flag & (1 << i)) == 0) {
        sp[step] = data[i];
        rec(flag | (1 << i), step + 1);
        sp[step] = strrev(&data[i]);
        rec(flag | (1 << i), step + 1);
      }
    }
  }
}
void solve() {
  cnt = 0;
  rec(0, 0);
  cout << cnt / 64 << endl;
}
int main() {
  while (1) {
    cin >> data[0];
    if (data[0] == "END") break;
    for (int i = 1; i < 10; i++) {
      cin >> data[i];
    }
    solve();
  }
}
