#include<stdio.h>
#include<string.h>
int tcn, n, tmp, x[200010], y[200010], cx[200010], cy[200010], a, b, k;;
int main() {
	scanf("%d", &tcn);
	for (int tc = 1; tc <= tcn; tc++) {
		scanf("%d %d %d", &a, &b, &k);
		for (int i = 1; i <= k; i++) {
			scanf("%d", &x[i]);
			cx[x[i]]++;
		}
		for (int i = 1; i <= k; i++) {
			scanf("%d", &y[i]);
			cy[y[i]]++;
		}
		long long int res = 0;
		for (int i = 1; i <= k; i++) {
			res += k + 1 - cx[x[i]] - cy[y[i]];
		}
		printf("%lld\n", res / 2);
		memset(cx, 0, sizeof(cx));
		memset(cy, 0, sizeof(cy));
	}
}