#include<iostream>
#include<sstream>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

const int r[][8] = {
	{1, 2, 3, 0, 5, 6, 7, 4},
	{1, 5, 6, 2, 0, 4, 7, 3}
};
set<int> s;
void rec(const vi &v){
	int h = 0;
	rep(i, 7) h *= 8, h += v[i];
	if(s.count(h)) return;
	s.insert(h);
	
	rep(d, 2){
		vi nv;
		rep(i, 8) nv.pb(v[r[d][i]]);
		rec(nv);
	}
}
int main(){
	string in[8];
	while(cin >> in[0]){
		rep(i, 7) cin >> in[i + 1];
		map<string, int> m;
		rep(i, 8) m[in[i]]++;
		vi v;
		int k = 0, ans = 0;
		each(i, m){
			rep(j, i->second) v.pb(k);
			k++;
		}
		s.clear();
		do{
			int h = 0;
			rep(i, 7) h *= 8, h += v[i];
			if(!s.count(h)){
				rec(v);
				ans++;
			}
		}while(next_permutation(all(v)));
		cout << ans << endl;
	}
	return 0;
}