#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};

LL pp[] = {1,10,100,1000,10000,100000,1000000,10000000,100000000};
LL ch[] = {0,3,7,4,1,2,6,5};
LL ch1[] = {0,4,5,1,3,7,6,2};
LL ch2[] = {6,5,4,7,2,1,0,3};

LL get_hash(LL k,LL i){
    return k * pp[i];
}


int main(){
    while(true){
        map<string,int> m;
        vector<int> a(8,0);
        int key = 0;
        for (int i = 0; i < 8; i++) {
            string s="";cin >> s;
            if(s=="") return 0;
            if(m.find(s)==m.end()) m[s] = key++;
            a[i] = m[s];
        }
        vector<int> v(8);
        for (int i = 0; i < 8; i++) {
            v[i] = i;
        }
        sort(RALL(a));
        int ans = 0;
        set<LL> st;
        auto f = [&](vector<LL> q){
            for (int p = 0; p < 2; p++) {
                for (int k = 0; k < 4; k++) {
                    auto b = q;
                    for (int i = 0; i < 4; i++) {
                        b[i] = q[(i+k)%4];
                        b[i+4] = q[(i+k)%4+4];
                    }
                    LL t = 0;
                    for (int i = 0; i < 8; i++) {
                        t += get_hash(b[i],i);
                    }
                    if(st.find(t) != st.end()) return false;
                }
                auto qq = q;
                for (int i = 0; i < 8; i++) {
                    q[i] = qq[ch2[i]];
                }
            }
            return true;
        };
        do{
            vector<LL> c(8);
            bool ff = true;
            for (int i = 0; i < 8; i++) {
                c[i] = a[v[i]];
            }
            auto cc = c;
            ff &= f(cc);
            for (int i = 0; i < 8; i++) {
                cc[i] = c[ch[i]];
            }
            ff &= f(cc);
            for (int i = 0; i < 8; i++) {
                cc[i] = c[ch1[i]];
            }
            ff &= f(cc);
            if(ff){
                ans++;
                LL t = 0;
                for (int i = 0; i < 8; i++) {
                    t += get_hash(c[i],i);
                }
                st.insert(t);
            }
        }
        while(next_permutation(ALL(v)));
        cout << ans << endl;
    }
    return 0;
}

