#include <bits/stdc++.h>
 
using namespace std;
namespace my_template
{
	#define ll long long
	#define pet pair<int,int>
	#define one first
	#define two second
 
	#define int long long
	#define all(x) x.begin(),x.end()
	#define pb push_back
	#define mp make_pair
	#define vi vector<int>
	#define vb vector<bool>
	#define vvi vector<vector<int>>
	#define res(v,n) v.resize(n)
	#define resn(v) v.resize(n)
	#define range(i,n) int i=0;i<n;i++
	#define range1(i,l,r) int i=l;i<r;i++
	#define range2(i,n,s) int i=0;i<n;i+=s
 
	vector<vector<int>> primes;
	vector<vector<int>> facts;
	vector<int> factorialNumInverse; 
	vector<int> naturalNumInverse; 
	vector<int> factorials; 
	
	int big=1e9+7;
	
	void InverseofNumber(ll N,ll p=big) 
	{ 
		naturalNumInverse[0] = naturalNumInverse[1] = 1; 
		for (int i = 2; i <= N; i++) 
			naturalNumInverse[i] = naturalNumInverse[p % i] * (p - p / i) % p; 
	} 
	void InverseofFactorial(ll N,ll p=big) 
	{ 
		factorialNumInverse[0] = factorialNumInverse[1] = 1;  
		for (int i = 2; i <= N; i++) 
			factorialNumInverse[i] = (naturalNumInverse[i] * factorialNumInverse[i - 1]) % p; 
	} 
	void factorial(ll N,ll p=big) 
	{ 
		factorials[0] = 1; 
	
		for (int i = 1; i <= N; i++) { 
			factorials[i] = (factorials[i - 1] * i) % p; 
		} 
	} 
	void setncr(ll size = 1e5+1,ll p = big)
	{
		factorialNumInverse.resize(size); 
		naturalNumInverse.resize(size); 
		factorials.resize(size);
	
		InverseofNumber(size,p);
		factorial(size,p);
		InverseofFactorial(size,p);
	}
	ll ncr(ll N, ll R, ll p=big) 
	{ 
		ll ans = ((factorials[N] * factorialNumInverse[R]) 
				% p * factorialNumInverse[N - R]) 
				% p; 
		return ans; 
	} 
	int power(int a,int b,int m=big)
	{
		if(b==0)
		return 1;
	
		int ans=power(a,b/2,m);
		if(b%2==0)
		return ans*ans%m;
	
		return ((a*ans)%m*ans)%m;
	}
	int inverse(int a,int m=big)
	{
		return power(a,m-2,m);
	}
	int ceil(int a,int b)
	{
		if(a==0)
		return 0;
	
		return (a-1)/b+1;
	}
	void init_prime(int size=1e6+1)
	{
		primes.resize(size);
	
		for(int i=2;i<size;i++)
		{
			if(primes[i].size()==0)
			{
				for(int j=i;j<size;j+=i)
				primes[j].push_back(i);
			}
		}
	}
	void init_facts(int size=2e5+1)
	{
		facts.resize(size);
	
		for(int i=1;i<size;i++)
		{
			for(int j=i;j<size;j+=i)
			facts[j].push_back(i);
		}
	}
	int gcd(int a,int b)
	{
		if(b==0)
		return a;
		
		return gcd(b,a%b);
	}
	template <typename T>
	vector<int> argsort(const vector<T> &v,bool reverse=false) 
	{
		vector<int> idx(v.size());
		iota(idx.begin(), idx.end(), 0);
	
		if(reverse == false)
		stable_sort(idx.begin(), idx.end(),
			[&v](int i1, int i2) {return v[i1]<v[i2];});
 
		else
		stable_sort(idx.begin(), idx.end(),
			[&v](int i1, int i2) {return v[i1]>v[i2];});
	
		return idx;
	}
}
using namespace my_template;
 
void solve();
signed main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
 
	// init_prime(2e5+1);
	// init_facts(1e5+1);
	// setncr(1e6+1);
 
	int t=1;
	cin >> t;
 
	while(t--)
	solve();
}
 
/*___________________________________________________________________________
 
								START
								FROM
								BELOW
 
***
 *                                                                ________  
 *    __________________     ____ ___.__._____    ____       ____ \_____  \ 
 *    \____ \_  __ \__  \   / ___<   |  |\__  \  /    \    _/ ___\ /  ____/ 
 *    |  |_> >  | \// __ \_/ /_/  >___  | / __ \|   |  \   \  \___/       \ 
 *    |   __/|__|  (____  /\___  // ____|(____  /___|  /____\___  >_______ \
 *    |__|              \//_____/ \/          \/     \/_____/   \/        \/
 *
_____________________________________________________________________________
*/
 
void solve()
{
	int a,b;
	cin >> a >> b;

	int k;
	cin >> k;

	map<int,int> m1,m2;

	int t1,t2;
	t2 = k;
	while(k--)
	{
		cin >> t1;
		m1[t1]++; 
	}

	k = t2;
	while(t2--)
	{
		cin >> t1;
		m2[t1]++;
	}

	int ans = 0;

	for(pet x:m1)
	{
		t1 = x.two;
		ans+=t1*(t1-1)/2;
	}

	for(pet x:m2)
	{
		t1 = x.two;
		ans+=t1*(t1-1)/2;
	}

	cout << k*(k-1)/2-ans << endl;
}