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

int main() {
	// your code goes here
	
	int t;cin>>t;
	
	while(t--)
	{
	    ll boys,girls,k;
	    cin>>boys>>girls>>k;
	    
	    unordered_map<int,int> boy,girl;
	    vector<pair<int,int>> inp(k);
	    
	    for(int i=0;i<k;i++)
	    {
	        int a; cin>>a;
	        inp[i].first = a;
	    }
	    for(int i=0;i<k;i++)
	    {
	        int a; cin>>a;
	        inp[i].second = a;
	    }
	    
	    for(int i=0;i<k;i++)
	    {
	        boy[inp[i].first]++;
	        girl[inp[i].second]++;
	    }
	    
	    ll ans = 0;
	    
	    for(int i=0;i<k;i++)
	    {
	        int a = inp[i].first;
	        int b = inp[i].second;
	        
	        ans += (k - (boy[a] + girl[b] - 1));
	    }
	    cout<<ans/2<<endl;
	}
	
	return 0;
}