#pragma  GCC optimize ("O3")
#pragma  GCC optimize("unroll-loops")
#pragma  GCC target("sse4")
#include <climits>
#include "iostream"
#include "cassert"
#include "cmath"
#include "cstdio"
#include "cstdlib"
#include "map"
#include "set"
#include "queue"
#include "vector"
#include "algorithm"
#include "numeric"
#include "unordered_map"
#include "cstring"
#include <stack>
#define mod 1000000007
#define LL long long int
using namespace std;
int main() 
{
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    LL T;
    cin >> T;
    while(T--)
    {
        LL a,b,k;
        cin >> a >> b >> k;
        vector<LL> arr1(k);
        vector<LL> arr2(k);
        for(auto &it:arr1)
        {
            cin >> it;
        }
        for(auto &it:arr2)
        {
            cin >> it;
        }
        map<LL,map<LL,LL> > r1;
        map<LL,map<LL,LL> > r2;
        // valid case wo honge jinpe A na hooo aur b bhi na ho isko nikalne ke liye 
        // (a,b ) jinpe a na hooo - jinpe b hooo aur a n hoooo  wo cases bhi to minus krne ha bsdkeeee 
        map<LL,LL> hash1;
        map<LL,LL> hash2;
        for(auto it:arr1)
        {
            hash1[it]++;
        }
        for(auto it:arr2)
        {
            hash2[it]++;
        }
        for(LL i=0;i<k;i++)
        {
            r1[arr1[i]][arr2[i]]++;
            r2[arr2[i]][arr1[i]]++;
        }
        LL ans=0;
        for(LL i=0;i<k;i++)
        {
            ans+=min( (   k-hash1[arr1[i]] - r2[arr2[i]].size() + r2[arr2[i]][arr1[i]]  ),(k-hash2[arr2[i]] - r1[arr1[i]].size() + r1[arr1[i]][arr2[i]]  ));
            //ans+= min( (k-hash1[arr1[i]]),(k-hash2[arr2[i]]));
        }
        cout<<ans/2<<endl;

    }
    

}