#include #include #include #include using namespace std; typedef long long ll; const int maxn = 100000 + 5; struct edge { int u, v; } G[maxn]; int son1[maxn], son2[maxn]; int main() { int T; scanf("%d", &T); while(T--) { int n, m, k; scanf("%d%d%d", &n, &m, &k); for(int i = 1; i <= n; ++i) son1[i] = 0; for(int i = 1; i <= m; ++i) son2[i] = 0; for(int i = 1; i <= k; ++i) { scanf("%d%d", &G[i].u, &G[i].v); ++son1[G[i].u], ++son2[G[i].v]; } ll ans = 0; for(int i = 1; i <= k; ++i) { ans += (son1[G[i].u] - 1LL) * (son2[G[i].v] - 1LL); } printf("%I64d\n", 2 * ans); } return 0; }