#include<bits/stdc++.h> using namespace std; struct s{ string first; string second; }x[110]; int main() { int n; cin >> n; for (int i = 1;i <= n;i ++) { string a,b; cin >> x[i].first >> a >> b >> x[i].second; } int ans = 0; for (int i = 1;i <= n;i ++) { for (int j = 1;j <= n;j ++) { for (int k = 1;k <= n;k ++) { for (int a = 1;a <= n;a ++) { if (x[i].second == x[j].first && x[j].second == x[k].first && x[k].second == x[a].first && x[a].second == x[i].first) { for (int b = 1;b <= n;b ++) { for (int c = 1;c <= n;c ++) { if (x[b].first == x[i].first && x[b].second == x[j].second) { if (x[c].first == x[i].second && x[c].second == x[k].second) { ans ++; } } } } } } } } } cout << ans; return 0; }