#include <bits/stdc++.h>
using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pi;

#define PB push_back
#define MP make_pair

typedef long long ll;

void print(int arr[], int n){

  for(int i=0; i<n; i++){
    cout<<arr[i]<<" ";
  }
  cout<<"\n";

}

#define FOR(i,a,b) for(int i=a; i<b; i++)

void solve(){

  int a,b,k;
  cin>>a>>b>>k;

  vector<pair<int,int>> arr;
  vi girls(b+1);
  vi boys(a+1);
  vi idek(k);
  long long int ans = 0;

  FOR(i,0,k){

    cin>>idek[i];
    boys[idek[i]]++;

  }

  FOR(i,0,k){
    int temp;
    cin>>temp;

    arr.PB(MP(idek[i],temp));
    girls[temp]++;

  }

  for(auto v:arr){
    ans = ans + k - girls[v.second] - boys[v.first] + 1;
  }

  cout<<ans/2<<"\n";

}

int main(){

  #ifndef ONLINE_JUDGE
      freopen("inputfa.txt", "r", stdin);
  #endif

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int t=1;
  cin>>t;
  while(t--){
    solve();
  }
  return 0;
}
