#include <iostream> using namespace std; #define int long long const int N = 100 + 5; string pv[N],nt[N]; signed main() { int n,cnt = 0; cin >> n; for (int i = 1; i <= n; i++) { string a,b,c,d; cin >> a >> b >> c >> d; pv[i] = a; nt[i] = d; } for (int a = 1; a <= n; a++) { for (int b = 1; b <= n; b++) { for (int c = 1; c <= n; c++) { for (int d = 1; d <= n; d++) { for (int e = 1; e <= n; e++) { for (int f = 1; f <= n; f++) { if (nt[a] == pv[b] && nt[b] == pv[d] && nt[d] == pv[c] && nt[c] == pv[a] && pv[e] == pv[a] && nt[e] == pv[d] && pv[f] == nt[a] && nt[f] == nt[d]) { cnt++; } } } } } } } cout << cnt; return 0; }