#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

struct P {
  vector<int> v;
  P(vector<int> &v) : v(v) {}
  P rotate1() {
    P r = *this;
    REP(i,3) swap(r.v[i],r.v[(i+1)%4]);
    REP(i,3) swap(r.v[4+i],r.v[4+(i+1)%4]);
    return r;
  }
  P rotate2() {
    vector<int> w = this->v;
    swap(w[0],w[4]);swap(w[4],w[5]);swap(w[5],w[1]);
    swap(w[2],w[3]);swap(w[3],w[7]);swap(w[7],w[6]);
    return P(w);
  }
  P rotate3() {
    vector<int> w = this->v;
    swap(w[0],w[4]);swap(w[4],w[7]);swap(w[7],w[3]);
    swap(w[1],w[5]);swap(w[5],w[6]);swap(w[6],w[2]);
    return P(w);
  }
  vector<P> all() {
    P r = *this;
    vector<P> res;
    for (int i=0; i<6; ++i,r=(i&2?r.rotate2():r.rotate3())) {
      for (int j=0;j<4; ++j,r=r.rotate1())
        res.push_back(r);
    }
    return res;
  }
};
int main() {
  string s;
  while(cin>>s) {
    map<string, int> mp;
    int num = 0;
    vector<int> v;
    mp[s] = num++;
    v.push_back(mp[s]);
    REP(i,7) {
      cin >> s;
      if (mp.count(s) == 0) mp[s] = num++;
      v.push_back(mp[s]);
    }
    vector<int> cnt(24);
    sort(ALL(v));
    do {
      vector<P> ret = P(v).all();
      REP(i,24) {
        if (ret[i].v == v) cnt[i]++;
      }
    } while(next_permutation(ALL(v)));
    int ans = 0;
    REP(i,24) ans += cnt[i];
    cout << ans/24 << endl;
  }
}