#include #include #include #include #include using namespace std; vector L[100020]; vector R[100020]; int x[100020]; int y[100020]; int main() { int t, n, m, k; scanf("%d", &t); for (int tt = 0; tt < t; tt++) { scanf("%d%d%d", &n, &m, &k); for (int i = 1; i <= n; i++) { L[i].clear(); } for (int i = 1; i <= m; i++) { R[i].clear(); } for (int i = 0; i < k; i++) { scanf("%d%d", &x[i], &y[i]); L[x[i]].push_back(y[i]); R[y[i]].push_back(x[i]); } long long ans = 0; for (int i = 0; i < k; i++) { ans += (long long)(L[x[i]].size() - 1) * (R[y[i]].size() - 1); } cout << ans * 2 << endl; } }