#include<bits/stdc++.h>
 
using namespace std;
 
#define sz(a) ((int)a.size())
 
typedef long long ll;
 
int main(){
    int t;
    scanf("%d",&t);
    while(t--){
        int a, b, k;
        scanf("%d%d%d",&a,&b,&k);
        ll ans = 0;
        int resto = k-1;
 
        int cntA[200005] = {0}, cntB[200005] = {0}, A[200005], B[200005];
 
        for(int i=0;i<k;i++){
            scanf("%d", A+i);
            cntA[ A[i] ]++;
        }
 
        for(int i=0;i<k;i++){
            scanf("%d", B+i);
            cntB[ B[i] ]++;
        }
 
        for(int i=0;i<k-1;i++){
            cntA[ A[i] ]--, cntB[ B[i] ]--;
            int qtd = resto - (cntA[ A[i] ] + cntB[ B[i] ]);
            ans+=qtd;
            resto--;
        }
 
        printf("%lld\n", ans);
 
    }
	return 0;
}