#include <bits/stdc++.h>

using namespace std;

#define REP(i, n) for (int i=0; i<(n); ++i)
#define RREP(i, n) for (int i=(int)(n)-1; i>=0; --i)
#define FOR(i, a, n) for (int i=(a); i<(n); ++i)
#define RFOR(i, a, n) for (int i=(int)(n)-1; i>=(a); --i)

#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl;

template<class T>
ostream &operator<<(ostream &os, const vector <T> &v) {
    os << "[";
    REP(i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}

template<class T, class U>
ostream &operator<<(ostream &os, const pair <T, U> &p) {
    return os << "(" << p.first << " " << p.second << ")";
}

template<class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;

const ll MOD = 1e9 + 7;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
const ld eps = 1e-9;

template<typename T>
struct edge {
    int src, to;
    T cost;
};

template<typename T>
using Graph = vector<vector<edge<T>>>;

using State = string::const_iterator;



int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    vvi perm;
    perm.push_back({0, 1, 3, 4, 2, 7, 5, 6});
    perm.push_back({0, 3, 4, 1, 7, 5, 2, 6});
    perm.push_back({0, 4, 1, 3, 5, 2, 7, 6});

    perm.push_back({1, 2, 0, 5, 3, 4, 6, 7});
    perm.push_back({1, 0, 5, 2, 4, 6, 3, 7});
    perm.push_back({1, 5, 2, 0, 6, 3, 4, 7});

    perm.push_back({2, 3, 1, 6, 0, 5, 7, 4});
    perm.push_back({2, 1, 6, 3, 5, 7, 0, 4});
    perm.push_back({2, 6, 3, 1, 7, 0, 5, 4});

    perm.push_back({3, 0, 2, 7, 1, 6, 4, 5});
    perm.push_back({3, 2, 7, 0, 6, 4, 1, 5});
    perm.push_back({3, 7, 0, 2, 4, 1, 6, 5});

    perm.push_back({4, 0, 7, 5, 3, 6, 1, 2});
    perm.push_back({4, 7, 5, 0, 6, 1, 3, 2});
    perm.push_back({4, 5, 0, 7, 1, 3, 6, 2});

    perm.push_back({5, 1, 4, 6, 0, 7, 2, 3});
    perm.push_back({5, 4, 6, 1, 7, 2, 0, 3});
    perm.push_back({5, 6, 1, 4, 2, 0, 7, 3});

    perm.push_back({6, 2, 5, 7, 1, 4, 3, 0});
    perm.push_back({6, 5, 7, 2, 4, 3, 1, 0});
    perm.push_back({6, 7, 2, 5, 3, 1, 4, 0});

    perm.push_back({7, 3, 6, 4, 2, 5, 0, 1});
    perm.push_back({7, 6, 4, 3, 5, 0, 2, 1});
    perm.push_back({7, 4, 3, 6, 0, 2, 5, 1});

    string s;
    vector<string> S;
    while (cin >> s) {
        S.push_back(s);
        if (S.size() < 8) continue;
        map<string,int> ord;
        for (string t : S) ord[t] = -1;
        int cnt = 0;
        for (auto &tp : ord) tp.second = cnt++;

        map<string,bool> sorted, mp;
        vector<int> a(8);
        iota(ALL(a), 0);

        do {
            set<string> codes;
            bool exist = 0;
            for (auto p : perm) {
                string t;
                for (int i : p) {
                    t += to_string(ord[S[a[i]]]);
                }
                if (mp.count(t)) {
                    exist = 1;
                    break;
                }
                codes.insert(t);
            }
            if (exist) continue;
            for (string t : codes) mp[t] = 1;
            sorted[*min_element(ALL(codes))] = 1;
        } while (next_permutation(ALL(a)));

        cout << sorted.size() << endl;
        S.clear();
    }

    return 0;
}




Measured memory_bytes: 7676