#include #define fst first #define snd second using namespace::std; typedef long long ll; typedef pair pii; const int maxn = 1e5 + 5; int n, m, k; ll b[maxn], g[maxn], res; pii p[maxn]; void solve() { res = 0; memset(b, 0, sizeof(b)); memset(g, 0, sizeof(g)); memset(p, 0, sizeof(p)); scanf("%d%d%d", &n, &m, &k); for (int i = 0; i < k; i++) { scanf("%d%d", &p[i].fst, &p[i].snd); b[p[i].fst]++; g[p[i].snd]++; } for (int i = 0; i < k; i++) { res += (b[p[i].fst] - 1) * (g[p[i].snd] - 1); } res *= 2; printf("%I64d\n", res); } int main() { int t; scanf("%d", &t); while (t--) { solve(); } return 0; }