#include <bits/stdc++.h>
std::string h[10005], t[10005];
std::map<std::string, std::vector<int>> m;
std::map<std::string, std::unordered_multiset<std::string>> sm; 
long long n, ans;
int main() {
	std::cin >> n;
	for (int i = 0; i < n; ++i) std::cin >> h[i] >> t[i] >> t[i] >> t[i], m[h[i]].push_back(i), sm[h[i]].insert(t[i]);
	for (int i = 0; i < n; ++i) for (auto j : m[t[i]]) if (sm[h[i]].find(t[j]) != sm[h[i]].end()) for (auto k : m[t[j]]) if (sm[t[i]].find(t[k]) != sm[t[i]].end()) for (auto l : m[t[k]]) ans += (t[l] == h[i]) * sm[h[i]].count(t[j]) * sm[t[i]].count(t[k]);
	std::cout << ans;
}