#include #include #include #include using namespace std; const int maxn=100005; int bo[maxn],g[maxn]; struct node{ int a,b; }ed[maxn]; int main() { int t; scanf("%d",&t); while(t--){ memset(bo,0,sizeof(bo)); memset(g,0,sizeof(g)); int n,m,k; scanf("%d%d%d",&n,&m,&k); for(int i=1;i<=k;i++){ scanf("%d%d",&ed[i].a,&ed[i].b); bo[ed[i].a]++,g[ed[i].b]++; } __int64 ans=0; for(int i=1;i<=k;i++){ int x=ed[i].a,y=ed[i].b; ans+=(__int64)2*(g[y]-1)*(bo[x]-1); } printf("%I64d\n",ans); } return 0; }