//to_string() convert int to string
// count count(all(v), element)
// cpresent for vector
// present for set
// string.substr(pos,length)
//memset(str, char, sizeof(str)) or it can used to initialize to values 0 or 1 
//map[key]=value
// it->first == (*it).first
//if n is even n&1 gives 0
#include<bits/stdc++.h>
#define present(container, element) (container.find(element) != container.end())
#define cpresent(container, element) (find(all(container),element) != container.end())
#define tr(container, it)  for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define all(x) x.begin(),x.end()
#define ll long long
#define pb push_back
#define fi first
#define se second
#define sz(a) a.size()
#define int long long int
#define rep(i,a,n) for(int i=a; i<n; i++)
using namespace std;
void solve()
{ 
    
    
    
   int a,b,k;
   cin>>a>>b>>k;
   vector<int>x(k);
   vector<int>y(k);
   map<int,int>ma;
   map<int,int>mb;
   
   rep(i,0,k)
   {cin>>x[i];
   ma[x[i]]++;
   }
   rep(i,0,k)
   {cin>>y[i];
   mb[y[i]]++;
   }
   int ans=0;
   for(int i=0; i<k; i++)
   {  ans+=(k-1)-(ma[x[i]]-1)-(mb[y[i]]-1);

   }
   cout<<ans/2<<endl;
   
   
   
   
   
}
signed main()
{ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin>>t;
while(t--)
solve();
return 0;

}