#include <set>
#include <cstdio>
#include <map>
#include <iostream>
#include <algorithm>
#include <queue>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#define f first
#define s second
#define mp make_pair

using namespace std;

template<class T>
class ID{
  map<T,int> _id;
public:
  ID(){}
  int operator()(const T &val){
    if(_id.find(val) == _id.end()){
      int next = _id.size();
      return _id[val] = next;
    }
    return _id[val];
  }
};

int main(){
  string s;
  while(cin >> s){
    vector<int> v(8);
    ID<string> id;
    v[0] = id(s);
    REP(i,7){
      cin >> s;
      v[i+1] = id(s);
    }

    set<string> ans;
    sort(v.begin(), v.end());

    do{
      vector<string> tmp(24, "        ");

      REP(i,4){
	REP(j,4){
	  tmp[i][(i+j)%4]   = v[j] + '0';
	  tmp[i][(i+j)%4+4] = v[j+4] + '0';

	  tmp[i+4][(i+j)%4]   = v[4+(3-j)] + '0';
	  tmp[i+4][(i+j)%4+4] = v[3-j] + '0';
	}
      }

      REP(i,8){
	tmp[i+8][0] = tmp[i][0];
	tmp[i+8][1] = tmp[i][3];
	tmp[i+8][2] = tmp[i][7];
	tmp[i+8][3] = tmp[i][4];
	tmp[i+8][4] = tmp[i][1];
	tmp[i+8][5] = tmp[i][2];
	tmp[i+8][6] = tmp[i][6];
	tmp[i+8][7] = tmp[i][5];
      }

      REP(i,8){
	tmp[i+16][0] = tmp[i][0];
	tmp[i+16][1] = tmp[i][4];
	tmp[i+16][2] = tmp[i][5];
	tmp[i+16][3] = tmp[i][1];
	tmp[i+16][4] = tmp[i][3];
	tmp[i+16][5] = tmp[i][7];
	tmp[i+16][6] = tmp[i][6];
	tmp[i+16][7] = tmp[i][2];
      }

      sort(tmp.begin(), tmp.end());
      ans.insert(tmp[0]);

    }while(next_permutation(v.begin(), v.end()));

    /*
    for(set<string>::iterator it = ans.begin();
	it != ans.end(); ++it){
      cout << *it << endl;
    }
    */


    printf("%d\n", ans.size());
  }
}