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

struct node {
	string a, b, c, d;
};
map<string, vector<node> >m;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin >> n;
	for(int i=1; i<=n; i++) {
		string a, b, c, d;
		cin >> a >> b >> c >> d;
		m[a].push_back((node) {a, b, c, d}); 
	}
	int ans=0;
	for(auto x: m) {
		vector<node>v=x.second;
		for(node i: v) {
			for(node j: m[i.d]) {
				for(node k: m[j.d]) {
					for(node l: m[k.d]) {
						if(l.d!=i.a)
							continue;
						for(node a: m[i.a]) {
							if(a.d!=j.d)
								continue;
							for(node b: m[i.d]) {
								if(b.d!=k.d)
									continue;
								node A[6]={i, j, k, l, a, b};
								bool flag=0;
								for(int I=0; I<6; I++)
									for(int J=I+1; J<6; J++)
										if(A[I].a==A[J].a&&A[I].b==A[J].b&&A[I].c==A[J].c&&A[I].d==A[J].d) {
											flag=1;
											break;
										}
								if(flag)
									continue;
								++ans;
							}
						}
					}
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}