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

int n,cnt = 0,a[10];

string s[10010][10],s1[10010],t[100010],ans[10][10];

map<string,int> mp;

vector<int> tou[10010],wei[10010];

bool g()
{
	for(int i = 1;i <= 6;i++)
	{
		for(int j = 1;j <= 6;j++)
		{
			if(i != j && a[i] == a[j])
			{
				return 0;
			}
		}
	}
	return 1;
}

int main()
{
	//freopen("idioms.txt","r",stdin);
	cin >> n;
	for(int i = 1;i <= n;i++)
	{
		for(int j = 1;j <= 4;j++)
		{
			string f;
			cin >> f;
			if(mp[f] == 0)
			{
				mp[f] = ++cnt;
			}
			s1[i] += s[i][j];
			s[i][j] = f;
		}
		tou[mp[s[i][1]]].push_back(i);
	}
	//cout << cnt << "\n";
	long long sum = 0;
	cnt = 0;
	for(int i = 1;i <= n;i++)
	{
		a[1] = i;
		for(auto t : tou[mp[s[i][4]]])
		{
			a[2] = t;
			for(auto u : tou[mp[s[t][4]]])
			{
				a[3] = u;
				for(auto y : tou[mp[s[u][4]]])
				{
					a[4] = y;
					if(s[y][4] == s[i][1])
					{
						for(auto t1 : tou[mp[s[i][1]]])
						{
							a[5] = t1;
							if(s[t1][4] == s[t][4])
							{
								for(auto m : tou[mp[s[i][4]]])
								{
									a[6] = m;
									if(m == t)
									{
										continue;
									}
									if(s[m][4] == s[y][1])
									{
										if(g())
										{
											cnt++;
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}
	cout << cnt << "\n";
	return 0;
}