#include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define rep(i,j,k) for (int i=j;i<=k;i++) #define Rrep(i,j,k) for (int i=j;i>=k;i--) #define Clean(x,y) memset(x,y,sizeof(x)) #define LL long long #define ULL unsigned long long #define inf 0x7fffffff #define mod 100000007 const int maxn = 200008; const int HHH = 100000; int n , m , k; int x[HHH+10] , y[HHH+10]; LL du[maxn]; LL ans; void init() { int tx , ty; scanf("%d%d%d",&n,&m,&k); rep(i,1,n) du[i] = 0; rep(j,1,m) du[j+HHH] = 0; rep(i,1,k) { scanf("%d%d",&tx,&ty); ty += HHH; x[i] = tx , y[i] = ty; du[tx]++ , du[ty]++; } ans = 0; rep(i,1,k) ans += (LL)( du[ x[i] ] - 1 ) * ( du[ y[i] ] - 1 ); printf("%I64d\n",ans<<1); } int main() { int T; cin>>T; while(T--) { init(); } return 0; }