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

typedef long long ll;
typedef vector<ll>vl1;
typedef vector<vl1> vl2;

vl1 veka(200001);
vl1 beka(200001);
vl1 kata(200001);
vl1 tata(200001);
struct struka
{ll val; ll ind;};
typedef vector<struka> vs;
vs sutra(11);

bool compa(struka& a, struka& b)
{ if(a.val==b.val) return a.ind<b.ind;
  return a.val<b.val;
}

int main()
{ ll i, j, k, kn, m, n, p, t, r, x, y, z, a, b, c;
  ll val, pos, tmp, suma, maxa, mina, naso, num, va, vb;
  string str1;
  char ch1;

  cin>>t;
  for(p=1;p<=t;p++)
   { cin>>va>>vb>>kn;
     for(i=1;i<=va;i++) kata[i]=0;
     for(i=1;i<=vb;i++) tata[i]=0;

     for(i=1;i<=kn;i++)
       { cin>>a;  veka[i]=a; kata[a]++; }
       for(i=1;i<=kn;i++)
       { cin>>b; beka[i]=b; tata[b]++; }

      suma=0;
      for(i=1;i<=kn;i++)
       { a=veka[i]; b=beka[i];
         suma+=(kn+1-tata[b]-kata[a]);
       }
      suma>>=1;
      cout<<suma<<'\n';
   }


  return 0;
}
/*
3
3 4 4
1 1 2 3
2 3 2 4
1 1 1
1
1
2 2 4
1 1 2 2
1 2 1 2
*/
