#include <bits/stdc++.h>
using namespace std;
string s[10];
int ans;
int f1;
string t[5], tt[5], pp[5];
bool b[111];
bool has[33644444];
int g11() {
  int q = 0;
  for (int i = 0; i < 5; i++)
    for (int j = 0; j < 5; j++)
      if (pp[i][j] == '1') q |= (1 << (i * 5 + j));
  return q;
}
int g12() {
  int q = 0;
  for (int i = 0; i < 5; i++) {
    for (int j = 0; j < 5; j++) {
      int i1 = (5 - i - 1);
      if (pp[i1][j] == '1') q |= (1 << (i1 * 5 + j));
    }
  }
  return q;
}
int g13() {
  int q = 0;
  for (int i = 0; i < 5; i++) {
    for (int j = 0; j < 5; j++) {
      int j1 = (5 - j - 1);
      if (pp[i][j1] == '1') q |= (1 << (i * 5 + j1));
    }
  }
  return q;
}
int g14() {
  int q = 0;
  for (int i = 0; i < 5; i++) {
    for (int j = 0; j < 5; j++) {
      int j1 = (5 - j - 1);
      int i1 = (5 - i - 1);
      if (pp[i1][j1] == '1') q |= (1 << (i1 * 5 + j1));
    }
  }
  return q;
}
void dfs2(int d) {
  if (d == 5) {
    for (int i = 0; i < 5; i++) pp[i] = tt[i];
    int p = g11();
    if (!has[p]) {
      ans++;
      has[p] = 1;
      p = g12();
      has[p] = 1;
      p = g13();
      has[p] = 1;
      p = g14();
      has[p] = 1;
    }
  } else {
    for (int i = 0; i < 10; i++) {
      if (!b[i]) {
        for (int o = 0; o < 2; o++) {
          reverse(s[i].begin(), s[i].end());
          int f = 0;
          for (int j = 0; j < 5; j++) {
            if (t[j][d] == s[i][j]) f++;
          }
          if (!f) {
            tt[d] = s[i];
            b[i] = 1;
            dfs2(d + 1);
            b[i] = 0;
          }
        }
      }
    }
  }
}
int g1() {
  int q = 0;
  for (int i = 0; i < 5; i++)
    for (int j = 0; j < 5; j++)
      if (t[i][j] == '1') q |= (1 << (i * 5 + j));
  return q;
}
int g2() {
  int q = 0;
  for (int i = 0; i < 5; i++) {
    for (int j = 0; j < 5; j++) {
      int i1 = (5 - i - 1);
      if (t[i1][j] == '1') q |= (1 << (i1 * 5 + j));
    }
  }
  return q;
}
int g3() {
  int q = 0;
  for (int i = 0; i < 5; i++) {
    for (int j = 0; j < 5; j++) {
      int j1 = (5 - j - 1);
      if (t[i][j1] == '1') q |= (1 << (i * 5 + j1));
    }
  }
  return q;
}
int g4() {
  int q = 0;
  for (int i = 0; i < 5; i++) {
    for (int j = 0; j < 5; j++) {
      int j1 = (5 - j - 1);
      int i1 = (5 - i - 1);
      if (t[i1][j1] == '1') q |= (1 << (i1 * 5 + j1));
    }
  }
  return q;
}
void dfs(int d) {
  if (d == 5) {
    int p = g1();
    if (!has[p]) {
      dfs2(0);
      has[p] = 1;
      p = g2();
      has[p] = 1;
      p = g3();
      has[p] = 1;
      p = g4();
      has[p] = 1;
    }
  } else {
    for (int i = 0; i < 10; i++)
      if (!b[i]) {
        b[i] = 1;
        t[d] = s[i];
        dfs(d + 1);
        reverse(t[d].begin(), t[d].end());
        dfs(d + 1);
        b[i] = 0;
      }
  }
}
int main() {
  while (cin >> s[0], s[0] != "END") {
    memset(b, 0, sizeof(b));
    for (int i = 0; i < 9; i++) cin >> s[i + 1];
    ans = 0;
    dfs(0);
    if (ans != 1)
      cout << ans / 4 << endl;
    else
      cout << 1 << endl;
  }
}
