#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
struct octa {
	int v[8];
	bool operator<(const octa &a) const {
		rep(i, 7) {
			if (a.v[i] != v[i])return a.v[i] > v[i];
		}
		return a.v[7] > v[7];
	}
};
octa turnright(octa x) {
	octa res;
	rep(i, 4) {
		res.v[i] = x.v[(i + 1) % 4];
		res.v[i + 4] = x.v[(i + 1) % 4 + 4];
	}
	return res;
}
octa rev(octa x) {
	octa res;
	res.v[0] = x.v[4];
	res.v[1] = x.v[7];
	res.v[2] = x.v[6];
	res.v[3] = x.v[5];
	res.v[4] = x.v[0];
	res.v[5] = x.v[3];
	res.v[6] = x.v[2];
	res.v[7] = x.v[1];
	return res;
}
octa turn2(octa x) {
	octa res;
	res.v[0] = x.v[0];
	res.v[1] = x.v[4];
	res.v[3] = x.v[1];
	res.v[4] = x.v[3];
	res.v[2] = x.v[5];
	res.v[5] = x.v[7];
	res.v[7] = x.v[2];
	res.v[6] = x.v[6];
	return res;
} 
int main() {
	string s;
	while (cin>>s) {
		map<octa, bool> mp;
		map<string, int> memo;
		int b[8];
		int id = 1;
		memo[s] = id;
		b[0] = id;
		rep1(i, 7) {
			cin >> s;
			if (!memo[s]) {
				id++;
				memo[s] = id;
				b[i] = id;
			}
			else {
				b[i] = memo[s];
			}
		}
		sort(b, b + 8);
		int out = 0;
		while (true) {
			octa y;
			octa y1, y2;
			rep(i, 8) {
				y.v[i] = b[i];
			}
			if(!mp[y]) {
				out++;
				y1 = turn2(y);
				y2 = turn2(y1);
				mp[y] = mp[y1] = mp[y2] = true;
				rep(i, 3) {
					y = turnright(y);
					y1 = turn2(y);
					y2 = turn2(y1);
					mp[y] = mp[y1] = mp[y2] = true;
				}
				y = rev(y);
				y1 = turn2(y);
				y2 = turn2(y1);
				mp[y] = mp[y1] = mp[y2] = true;
				rep(i, 3) {
					y = turnright(y);
					y1 = turn2(y);
					y2 = turn2(y1);
					mp[y] = mp[y1] = mp[y2] = true;
				}
			}
			if (!next_permutation(b, b + 8))break;
		}
		cout << out << endl;
	}
	return 0;
}
