#include <bits/stdc++.h> #define BASE 31 #define MOD (unsigned long long)1e9 + 7 #define PRIME 229897 using namespace std; typedef unsigned long long ull; char s1[1007],s2[1007],s3[1007],s4[1007]; int n,ans; ull a[10000][5],x,h[1007]; map<ull,int>m1,m2,m3,m4; map<pair<ull,ull>,int>r; int main(){ //freopen("idioms.txt","r",stdin); ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); //Do not need freopen; h[0] = 1; for (int i = 1;i <= 1001;i++){ h[i] = (h[i - 1] * BASE + PRIME) % MOD; } cin >> n; for (int i = 1;i <= n;i++){ cin >> s1 >> s2 >> s3 >> s4; x = 0; for (int j = 1;j <= strlen(s1);j++){ x = (x + (int)s1[j - 1] * h[j]) % MOD; } a[i][0] = x; x = 0; for (int j = 1;j <= strlen(s2);j++){ x = (x + (int)s2[j - 1] * h[j]) % MOD; } a[i][1] = x; x = 0; for (int j = 1;j <= strlen(s3);j++){ x = (x + (int)s3[j - 1] * h[j]) % MOD; } a[i][2] = x; x = 0; for (int j = 1;j <= strlen(s4);j++){ x = (x + (int)s4[j - 1] * h[j]) % MOD; } a[i][3] = x; //cout << "* " << s1 << " " << s2 << " " << s3 << " " << s4 << endl; //cout << "# " << a[i][0] << " " << a[i][1] << " " << a[i][2] << " " << a[i][3] << endl; m1[a[i][0]]++; m2[a[i][1]]++; m3[a[i][2]]++; m4[a[i][3]]++; r[pair<ull,ull>(a[i][0],a[i][3])] = 1; } ans = 0; for (int i = 1;i <= n;i++){ if (m1[a[i][0]] >= 2 && m4[a[i][0]] >= 1 && m1[a[i][3]] >= 2 && m4[a[i][3]] >= 1){ for (int j = 1;j <= n;j++){ if (i != j && m1[a[j][0]] >= 1 && m4[a[j][0]] >= 2 && m1[a[j][3]] >= 1 && m4[a[j][3]] >= 2 && \ r[pair<ull,ull>(a[i][0],a[j][0])] && r[pair<ull,ull>(a[i][3],a[j][3])] && r[pair<ull,ull>(a[j][3],a[i][0])] && \ r[pair<ull,ull>(a[i][3],a[j][0])]){ ans++; } } } } cout << ans << endl; return 0; }