#include #include #include #include #include #include #include #include typedef std::bitset<32> B32; typedef unsigned int TYPE; inline int input() { static int c,t;static int k;k=0;t=1; do c=getchar(); while((c<'0'||c>'9')&&c!='-'); if(c=='-')c=getchar(),t=-1; do k=k*10+c-'0',c=getchar(); while(c>='0'&&c<='9'); return k*t; } const int MAXN=200010; int cal[MAXN],a[MAXN],b[MAXN]; int main() { int T=input(); while(T-->0) { memset(cal,0,sizeof(cal)); int N=input(),M=input(),K=input(); for(int i=1;i<=K;++i) { a[i]=input(); b[i]=input(); ++cal[a[i]]; ++cal[b[i]+N]; } long long ans=0; for(int i=1;i<=K;++i) { ans+=1ll*(cal[a[i]]-1)*(cal[b[i]+N]-1); }std::cout<<(ans<<1)<