#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
ll n,ans;const ll N=10015,bs=37;
string x1[N],x2[N],x3[N],x4[N];
map<ll,ll> bgw;
map<ll,ll> edw;
ll hs(string s){
	ll x=0;
	for(char c:s){
		x=x*bs+(isdigit(c)?c-48:c-97+10);
	}
	return x;
}
ll jc[]={1,1,2,6,24,120,720,5040};
ll C(ll x,ll y){if(y>x)return 0;return jc[x]/jc[y]/jc[x-y];}
signed main(){
	//freopen("xxx.in","r",stdin);
	//freopen("xxx.out","w",stdout);
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin>>n;
	for(ll i=1;i<=n;i++){
		cin>>x1[i]>>x2[i]>>x3[i]>>x4[i];
		bgw[hs(x1[i])]++;
		edw[hs(x4[i])]++;
	}
	for(ll i=1;i<=n;i++){
		for(ll j=1;j<=n;j++){
			if(i==j)continue;
			ll w=hs(x1[i]);
			ll z=hs(x4[i]);
			ll c=hs(x1[j]);
			ll d=hs(x4[j]);
			ll a=bgw[w]*edw[c];
			ll b=bgw[w]*edw[z];
			ll g=bgw[d]*edw[w];
			ll h=bgw[z]*edw[c];
			ll e=bgw[z]*edw[d];
			ll f=bgw[c]*edw[d];
			if(w==z&&z==c&&c==d){
				ll q=bgw[w]*edw[z];if(q<6)ans+=0;else ans+=q*(q-1)/2*(q-2)/3*(q-3)/4*(q-4)/5*(q-5)/6;
			}else if(w==z&&z==d){
				ans+=C(b,3)*C(a,2)*g;
			}else if(w==z&&z==c){
				ans+=C(a,3)*C(f,2)*g;
			}else if(c==z&&c==d){
				ans+=C(e,3)*C(a,2)*g;
			}else if(w==c&&c==d){
				ans+=C(a,3)*C(b,2)*b;
			}else if(w==z){
				ans+=a*b*g*(h-1)*e*f;
			}else if(w==c){
				ans+=a*b*g*h*e*f;
			}else if(w==d){
				ans+=a*b*g*h*e*f;
			}else if(d==z){
				ans+=a*b*g*h*e*f;
			}else if(c==z){
				ans+=(a-1)*b*g*h*f*(e-1);
			}else if(d==c){
				ans+=a*b*g*(h-1)*e*f;
			}else{
				ans+=a*b*g*h*e*f;
			}
		}
	}cout<<ans;
	return 0;
}