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

#define pb push_back
#define mp make_pair
#define se second
#define fi first
#define ll long long

int main()
{
	int tc;
	cin>>tc;
	while(tc--)
	{
		int a,b,k;
		cin>>a>>b>>k;
		
		int arra[a+1];
		int arrb[b+1];
		memset(arra,0,sizeof arra);
		memset(arrb,0,sizeof arrb);
		
		int p[k+1][2];
		
		for(int i=1;i<=k;i++)
		{
			cin>>p[i][0];
			arra[p[i][0]]++;
		}
		for(int i=1;i<=k;i++)
		{
			cin>>p[i][1];
			arrb[p[i][1]]++;
		}
		
		//for(int i=1;i<=k;i++) cout<<p[i][0]<<" "<<p[i][1]<<endl;
		
		ll cnt=0;
		for(int i=1;i<=k;i++)
		{
			int add=k-arra[p[i][0]]-arrb[p[i][1]]+1;
			cnt+=add;
		}
		
		cout<<cnt/2<<endl;
	}
}