
// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")

//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)
#pragma GCC optimize("unroll-loops")
// -------------------</optimizations>--------------------
#include <iostream>
#include <bitset>
#include <algorithm>        // sort()
#include <vector>           // for vectors
#include <map>              // for ordered map
#include <unordered_map>
#include <list>             // for list
#include <iomanip>          // for setprecision()
#include <cmath>            // for pow(), sqrt(), log(), log10(), ....
#include <cstring>          // for memset()
#include <unordered_set>    // for unordered_set
#include <climits>          // for INT_MAX & INT_MIN
#include <set>              // for ordered set

#define C ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
typedef long long ll;
#define INF INT_MAX
#define NINF INT_MIN
#define MOD 1000000007
const double pi=acos(-1); // value of pi


bool isVowel(char ch) {
    if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u') {
        return 1;
    }
    return 0;
}

bool compare(pair<ll, ll> a, pair<ll, ll> b) {
    return a.second<b.second;
}


bool isPrime(ll n) {
    if(n%2==0 && n!=2) {
        return false;
    }
    for(ll i=3; i*i<=n; i+=2) {
        if(n%i==0) {
            return false;
        }
    }
    return true;
}

ll binary_exp(ll x, ll n, ll mod)
{
    if (n == 0) {
        return 1;
    } else if (n == 1) {
        return x % mod;
    } else {
        ll temp = binary_exp(x, n / 2, mod);
        temp = (temp * temp) % mod;

        if (n % 2 == 0) {
            return temp;
        } else {
            return ((x % mod) * temp) % mod;
        }
    }
}

bool isPalin(string s) {
    ll n=s.length();
    for(ll i=0; i<n/2; i++) {
        if(s[i]!=s[n-1-i] || s[i]=='$' || s[n-i-1]=='$') {
            return false;
        }
    }
    return true;
}

// map<ll, ll> m;

int main() {
    C
//     freopen("input.txt","r",stdin);
// 	freopen("output.txt","w",stdout);
    int t=1;
    cin >> t;
    while(t--) {
        ll n, m, k, x, y, ans=0;
        cin >> n >> m >> k;
        map<ll, ll> b, g;
        vector<pair<ll, ll>> v;
        for(ll i=0; i<k; i++) {
            cin >> x;
            v.push_back({x, 0});
            b[x]++;
            g[y]++;
        }
        for(ll i=0; i<k; i++) {
            cin >> x;
            v[i].second=x;
            g[x]++;
        }
        ll w=k;
        w--;
        for(ll i=0; i<k; i++) {
            ll q=b[v[i].first];
            ll p=g[v[i].second];
            ans+=w-q-p+2;
            b[v[i].first]--;
            g[v[i].second]--;
            w--;
        }
        cout << ans << endl;
    }
}
