#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(a) (a).begin(),(a).end()
using namespace std;
typedef vector<int> vi;
typedef unsigned long long ull;

int rot[] = {0,4,5,1,3,7,6,2};
vector<vi> rots;

void next(vi &x){
  rep(i,3){
    swap(x[i],x[i+1]);
    swap(x[i+4],x[i+5]);
  }
}

ull t[1<<18];

int main(){
  vi tmp;
  rep(i,8)tmp.push_back(i);
  rots.push_back(tmp);
  rep(i,3){
    next(tmp);
    rots.push_back(tmp);
  }

  rep(i,4){
    tmp = rots[i];
    reverse(all(tmp));
    rots.push_back(tmp);
  }

  rep(i,16){
    tmp.resize(8);
    rep(j,8)tmp[j] = rots[i][rot[j]];
    rots.push_back(tmp);
  }

  string s;
  while(cin >> s){
    map<string,int> m;
    m[s]++;
    rep(i,7)cin >> s, m[s]++;
    vi v;
    int id=0;
    for(map<string,int>::iterator it=m.begin();it!=m.end();it++){
      rep(i,it->second)v.push_back(id);
      id++;
    }

    int ans = 0;
    rep(i,1<<18)t[i] = 0ULL;

    do{
      int h = 0;
      rep(i,8)h*=8,h+=v[i];
      if( !((t[h>>6]>>(h&63))&1ULL) ){
	rep(i,24){
	  h = 0;
	  rep(j,8)h*=8,h+=v[rots[i][j]];
	  t[h>>6] |= 1ULL<<(h&63);
	}
	ans++;
      }
    }while(next_permutation(all(v)));

    cout << ans << endl;
  }
}