#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
    int t;
    cin>>t;
    while(t-->0){
        ll a,b,k;
        cin>>a>>b>>k;
        ll f1[a+1];
        ll f2[b+1];
        memset(f1,0,sizeof(f1));
        memset(f2,0,sizeof(f2));
        for(int i=0;i<k;i++){
            int data;
            cin>>data;
            f1[data]++;
        }
        for(int i=0;i<k;i++){
            int data;
            cin>>data;
            f2[data]++;
        }
        ll res=0;
        for(int i=1;i<=a;i++){
            if(f1[i]>=2){
                res+=((f1[i]*(f1[i]-1)))/2;
            }
        }
        for(int i=1;i<=b;i++){
            if(f2[i]>=2){
                res+=((f2[i]*(f2[i]-1)))/2;
            }
        }
        ll result=((k*(k-1))/2-res);
        cout<<result<<"\n";
    }
}