#include #include #include #include #include #include #include #include #include #include #define pb push_back #define lb lower_bound #define lowbit(x) (x)&(-x) #define forup(i,a,b) for(int i=(a);i<=(b);i++) #define fordown(i,a,b) for(int i=(a);i>=(b);i--) #define maxn 1000005 #define INF 107000000 #define mod 997 using namespace std; typedef long long ll; typedef unsigned long long ull; template inline void read(T& num){ num = 0; bool f = true;char ch = getchar(); while(ch < '0' || ch > '9') { if(ch == '-') f = false;ch = getchar();} while(ch >= '0' && ch <= '9') {num = num * 10 + ch - '0';ch = getchar();} num = f ? num: -num; } int out[100]; template inline void write(T x,char ch){ if (x==0) {putchar('0'); putchar(ch); return;} if (x<0) {putchar('-'); x=-x;} int num=0; while (x){ out[num++]=(x%10); x=x/10;} fordown(i,num-1,0) putchar(out[i]+'0'); putchar(ch); } /*========================================================*/ int n,m,k; int len[maxn][2]; vector g[maxn]; void clearall() { forup(i,1,n+m) g[i].clear(); } int main() { int T; cin>>T; while(T--) { cin>>n>>m>>k; clearall(); forup(i,1,k) { int x,y;read(x);read(y); y=n+y; g[x].pb(y);g[y].pb(x); len[i][0]=x;len[i][1]=y; } ll ans=0; forup(i,1,k) { int x=len[i][1],y=len[i][0]; ll tmp=(ll)(g[x].size()-1)*(g[y].size()-1); ans+=tmp; } cout<