#include #include #include #include #include using namespace std; #define maxn 100005 typedef __int64 ll; vectorq[maxn]; ll t1[maxn],t2[maxn]; struct node { ll x,y; }a[maxn]; int main() { ll T,n,m,k,i,ans; scanf("%d",&T); while(T--) { ans=0; scanf("%I64d%I64d%I64d",&n,&m,&k); for(i=1;i<=k;i++) { scanf("%I64d%I64d",&a[i].x,&a[i].y); t1[a[i].x]++; t2[a[i].y]++; } for(i=1;i<=k;i++) ans+=(ll)(t1[a[i].x]-1)*(t2[a[i].y]-1)*2; for(i=1;i<=k;i++) { t1[a[i].x]=0; t2[a[i].y]=0; } printf("%I64d\n",ans); } }