/* ACM ICPC Asia 98 Tokyo Problem B: Lattice Practices by Naoyuki Tamura (tamura@kobe-u.ac.jp) */ import java.io.*; import java.util.*; public class B { static boolean dbg = false; static DataInputStream in = new DataInputStream(System.in); static int N = 5; static int N2 = 2*N; static String board[] = new String[N2]; static int count = 0; static String sol[] = new String[N2]; static boolean used[] = new boolean[N2]; static String b0; static void debug(String msg) { if (dbg) System.err.print(msg); } static boolean read() throws Exception { String line = null; debug("# Enter\n"); line = in.readLine(); if (line.equals("END")) return false; StringTokenizer st = new StringTokenizer(line); for (int i = 0; i < N2; i++) { board[i] = st.nextToken(); } return true; } static void init() throws Exception { for (int i = 0; i < N2; i++) { b0 = board[i]; if (! b0.equals(rev(b0))) break; } count = 0; for (int i = 0; i < N2; i++) used[i] = false; } static boolean solution() throws Exception { for (int i = N; i < N2; i++) { if (! match(i)) return false; } return true; } static boolean canonical() throws Exception { for (int i = 0; i < 3; i++) { if (sol[i].equals(b0)) { if (i == 2) return sol[0].compareTo(sol[N-1]) < 0; else return true; } } return false; } static boolean check(int n) throws Exception { if (n == 2) { for (int i = 0; i < 3; i++) if (sol[i].equals(b0)) return true; return false; } return n < N || match(n); } static boolean match(int j) throws Exception { for (int i = 0; i < N; i++) { if (sol[i].charAt(j-N) == sol[j].charAt(i)) return false; } return true; } static String rev(String s) throws Exception { int n = s.length(); int i, j; StringBuffer r = new StringBuffer(n); r.setLength(n); for (i = 0, j = n-1; i < n; i++, j--) r.setCharAt(i, s.charAt(j)); return r.toString(); } static void solve(int n) throws Exception { if (n == N2) { if (solution() && canonical()) { printSol(n); count++; } } else { for (int i = 0; i < N2; i++) { if (! used[i]) { used[i] = true; String b = board[i]; sol[n] = b; if (check(n)) solve(n + 1); if (! b.equals(rev(b))) { sol[n] = rev(b); if (check(n)) solve(n + 1); } used[i] = false; } } } } static void printSol(int n) { debug("#"); for (int i = 0; i < n; i++) { debug(" " + sol[i]); } debug("\n"); } public static void main(String args[]) { if (args.length > 0) dbg = true; try { while (read()) { init(); solve(0); System.out.println(count); } } catch (Exception e) { e.printStackTrace(); } } }