#include <bits/stdc++.h>
using namespace std;

int64_t encode(vector<int>& c){
    int64_t ret = 1e18;
    for(int i=0; i<4; i++){
        int64_t result = 0;
        for(int j=0; j<4; j++){
            result *= 1000;
            result += c[(i+j)%4];
        }
        ret = min(ret, result);
    }
    return ret;
}

int main(){
    int N;
    cin >> N;
    vector<int> C[400];
    map<int64_t, int> mp;
    for(int i=0; i<N; i++){
        C[i].resize(4);
        for(int j=0; j<4; j++) cin >> C[i][j];
        mp[encode(C[i])]++;
    }

    int64_t ans = 0;
    for(int i=0; i<N; i++){
        int64_t ci = encode(C[i]);
        mp[ci]--;
        for(int j=i+1; j<N; j++){
            int64_t cj = encode(C[j]);
            mp[cj]--;

            for(int k=0; k<4; k++){
                int64_t result = 1;
                vector<int64_t> use;
                for(int l=0; l<4; l++){
                    vector<int> c = {C[i][(l+1)%4], C[i][l], C[j][(3-l+k)%4], C[j][(3-l-1+k+4)%4]};
                    int64_t code = encode(c);
                    if(mp[code] > 0){
                        result *= mp[code];
                        if(c[0]==c[2] && c[1]==c[3]){
                            result *= (c[0]==c[1] ? 4 : 2);
                        }
                        mp[code]--;
                        use.push_back(code);
                    }else{
                        result = 0;
                        break;
                    }
                }
                ans += result;
                for(auto code : use) mp[code]++;
            }

            mp[cj]++;
        }
        mp[ci]++;
    }
    cout << ans/3 << endl;
    return 0;
}