#include<iostream>
#include<map>
#include<cmath>
#include<set>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
int table[6][8]={
  {0,1,2,3,4,5,6,7},
  {4,7,6,5,0,3,2,1},
  {0,4,5,1,3,7,6,2},
  {1,5,6,2,0,4,7,3},
  {2,6,7,3,1,5,4,0},
  {3,7,4,0,2,6,5,1}
};



class state{
public:
  char data[8];
  bool operator<(const state & a)const {
    rep(i,8)
      if( data[i] != a.data[i])return data[i]<a.data[i];
    return false;
  }
};


bool check_duplicate(state & a,set<state> &S){
  state check[4];
  rep(i,4){
    rep(j,4){
      check[i].data[j]    =a.data[(i+j)%4];
      check[i].data[4+j]  =a.data[4+(4+i+j)%4];
    }
  }
  
  rep(i,8)if ( S.find(check[i]) !=S.end())return true;
  return false;
}

int cpy[8]={4,7,6,5,0,3,2,1};

void make_set(state & a,set<state> & S){
  state check;
  state check2;
  rep(i,6){
    rep(j,8)check.data[j]=a.data[table[i][j]];
    if (check_duplicate(check,S))return;
    rep(j,8)check2.data[j]=check.data[cpy[j]];
    if (check_duplicate(check,S))return;
  }
  
  S.insert(a);
}


void generate(int num,int *rem,state &a,int now,set<state>&S){
  if ( now == 8){
    make_set(a,S);
    return;
  }
  rep(i,num){
    if( rem[i] == 0)continue;
    rem[i]--;
    a.data[now]=i;
    generate(num,rem,a,now+1,S);
    rem[i]++;
  }

} 


int main(){
  string a;
  while(cin>>a ){
    char index=0;
    int rem[8]={0};
    map<string,char> M;
    M[a]=(char)index++;
    rem[M[a]]++;
    REP(i,1,8){
      cin>>a;
      if ( M.find(a) == M.end())
      M[a]=(char)index++;
      rem[M[a]]++;
    }
    state ini;
    set<state> S;
    generate(M.size(),rem,ini,0,S);
    cout << S.size() << endl;
    /*
    set<state>::iterator itr = S.begin();
    while(itr != S.end()){
      puts("upper");
      rep(i,4)
	cout << (int)(*itr).data[i];
      puts("");
      puts("lower");
      rep(i,4)cout << (int)(*itr).data[i+4];
      puts("");
      itr++;
    }
    */
  }
  return false;
}
  