#include #include #include #include #include #include #include #include #include #include #include using namespace std; #define mem(x,y) memset(x,y,sizeof(x)) #define pb push_back #define bug puts("==========="); #define REP(i,n) for(int i=0;i pii; #define CHG ch=getchar() #define FRD x=bo=0; for(CHG;ch<'0'||ch>'9';CHG) if(ch=='-')bo=1; #define FR2 for(;ch>='0'&&ch<='9';x=(x<<1)+(x<<3)+ch-'0',CHG); char ch; int bo; inline bool blank(char ch){return ch==' '||ch=='\n'||ch=='\r'||ch=='\t';} inline void RD(int &x){ FRD FR2 if (bo)x=-x; } inline void RD(ll &x){ FRD FR2 if (bo)x=-x; } inline ll RD(){ ll x; RD(x); return x; } inline void RD(char *s){///scanf %s for (CHG;blank(ch);CHG); for (;!blank(ch);CHG)*s++=ch; *s=0; } inline void RD(char &c){for(CHG;blank(c);CHG);} template inline void OT(T x){ static char buf[20]; char *p1=buf;if (!x)*p1++='0';if (x<0)putchar('-'),x=-x; while(x)*p1++=x%10+'0',x/=10; while(p1--!=buf)putchar(*p1); } inline void pe(){puts("");}//输出回车 inline void pk(){putchar(' ');}//输出空格 const double eps=1e-8; const ll inf=2e9; const int maxn=1e5+70; const ll mod =100000007; /*======================================*/ vector v1[maxn],v2[maxn]; int main() { T_T{ int n,m,k; scanf("%d%d%d",&n,&m,&k); REP(i,n)v1[i].clear(); REP(j,m)v2[j].clear(); REP(i,k){ int a,b; RD(a),RD(b); a--,b--; v1[a].pb(b); v2[b].pb(a); } REP(i,n) { sort(ALL(v1[i])); v1[i].resize(unique(ALL(v1[i]))-v1[i].begin()); } REP(i,m) { sort(ALL(v2[i])); v2[i].resize(unique(ALL(v2[i]))-v2[i].begin()); } ll ans=0; REP(i,n) { REP(j,v1[i].size()) ans+=(v1[i].size()-1)*(v2[v1[i][j]].size()-1)*2; } OT(ans),pe(); } return 0; }