/* *********************************************** Author: SnowyJune Created Time :2017年02月25日 星期六 19时13分41秒 File Name :B.cpp ************************************************ */ #include #include #include #include #include #include #include #include #include #include #include #include #define lson(x) (x<<1) #define rson(x) ((x<<1)|1) #define ms(a,x) memset(a,x,sizeof(a)) typedef long long LL; #define pi pair < int ,int > #define MP make_pair using namespace std; const double eps = 1E-8; const int dx4[4]={1,0,0,-1}; const int dy4[4]={0,-1,1,0}; const int INF = 0x3f3f3f3f; const LL LINF = 0x3f3f3f3f3f3f3f3f; const int maxn = 2e5+10; LL deg[maxn], u[maxn], v[maxn]; int n,m,k; void init(){ int tmpx,tmpy; scanf("%d%d%d",&n,&m,&k); if(n > 1000)memset(deg,0,sizeof(deg)); else memset(deg,0,sizeof(LL) * 2005); for(int i = 1; i <= k; i++){ scanf("%d%d",&tmpx,&tmpy); tmpy += n; deg[tmpx] ++, deg[tmpy]++; u[i] = tmpx, v[i] = tmpy; } } LL calc(){ LL res = 0; for(int i = 1; i <= k; i++){ res += (deg[u[i]]-1) * (deg[v[i]]-1); } return (res << 1); } int main(){ #ifdef SNOWYJUNE freopen("input","r",stdin); #endif int T; scanf("%d",&T); while(T--){ init(); printf("%I64d\n",calc()); } #ifdef SNOWYJUNE fclose(stdin); #endif return 0; }