1 //B-用map写,学一手-跑过了
2 #include<iostream>
3 #include<cstring>
4 #include<cstdio>
5 #include<algorithm>
6 #include<cmath>
7 #include<map>
8 using namespace std;
9 typedef long long ll;
10 int main(){
11 int t,n;
12 scanf("%d",&t);
13 while(t--){
14 scanf("%d",&n);
15 map<int ,int>ma;
16 map<int ,int>mb;
17 for(int i=0;i<n;i++){
18 int x,y;
19 scanf("%d%d",&x,&y);
20 ma[x]++;
21 mb[y]++;
22 }
23 map<int ,int>::iterator it;
24 ll ans=0;
25 for(it=ma.begin();it!=ma.end();it++){
26 int s1=it->first;
27 int s2=it->second;
28 ans+=(ll)mb[s1]*s2;
29 }
30 printf("%lld
",ans);
31 }
32 return 0;
33 }