There is a city that can be represented as a square grid with corner points in (0, 0) and (10^6, 10^6).

The city has n vertical and m horizontal streets that goes across the whole city, i. e. the i-th vertical streets goes from (x_i, 0) to (x_i, 10^6) and the j-th horizontal street goes from (0, y_j) to (10^6, y_j). 

All streets are bidirectional. Borders of the city are streets as well.

There are k persons staying on the streets: the p-th person at point (x_p, y_p) (so either x_p equal to some x_i or y_p equal to some y_j, or both).

Let's say that a pair of persons form an inconvenient pair if the shortest path from one person to another going only by streets is strictly greater than the Manhattan distance between them.

Calculate the number of inconvenient pairs of persons (pairs (x, y) and (y, x) are the same pair).

Let's recall that Manhattan distance between points (x_1, y_1) and (x_2, y_2) is |x_1 - x_2| + |y_1 - y_2|.

Input

The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases.

The first line of each test case contains three integers n, m and k (2 ≤ n, m ≤ 2 ⋅ 10^5; 2 ≤ k ≤ 3 ⋅ 10^5) — the number of vertical and horizontal streets and the number of persons.

The second line of each test case contains n integers x_1, x_2, ..., x_n (0 = x_1 < x_2 < ... < x_{n - 1} < x_n = 10^6) — the x-coordinates of vertical streets.

The third line contains m integers y_1, y_2, ..., y_m (0 = y_1 < y_2 < ... < y_{m - 1} < y_m = 10^6) — the y-coordinates of horizontal streets.

Next k lines contains description of people. The p-th line contains two integers x_p and y_p (0 ≤ x_p, y_p ≤ 10^6; x_p ∈ \\{x_1, ..., x_n\} or y_p ∈ \\{y_1, ..., y_m\}) — the coordinates of the p-th person. All points are distinct.

It guaranteed that sum of n doesn't exceed 2 ⋅ 10^5, sum of m doesn't exceed 2 ⋅ 10^5 and sum of k doesn't exceed 3 ⋅ 10^5.

Output

For each test case, print the number of inconvenient pairs.

Example

Input


2
2 2 4
0 1000000
0 1000000
1 0
1000000 1
999999 1000000
0 999999
5 4 9
0 1 2 6 1000000
0 4 8 1000000
4 4
2 5
2 2
6 3
1000000 1
3 8
5 8
8 8
6 8


Output


2
5

Note

The second test case is pictured below: 

<image>

For example, points 3 and 4 form an inconvenient pair, since the shortest path between them (shown red and equal to 7) is greater than its Manhattan distance (equal to 5).

Points 3 and 5 also form an inconvenient pair: the shortest path equal to 1000001 (shown green) is greater than the Manhattan distance equal to 999999.

But points 5 and 9 don't form an inconvenient pair, since the shortest path (shown purple) is equal to its Manhattan distance.
/* Every moment is a moment of decision, and every moment turns us inexorably in the direction of the rest of our lives */
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#pragma GCC optimize ("-O3")
#define ll long long int
#define ld long double
#define ff first
#define ss second
/*-----------------------------------------------DEBUG FUNCTIONS----------------------------------------------------------------------------------------------------------------------------------------------------*/
#ifdef YuvrajSharma
#define deb(...) cerr << "(" << #__VA_ARGS__ << "): ", debug(__VA_ARGS__),cerr<<endl;
#else
#define deb(...);
#endif
void debug(ll t) {cerr << t;}
void debug(int t) {cerr << t;}
void debug(string t) {cerr << t;}
void debug(char t) {cerr << t;}
void debug(ld t) {cerr << t;}
void debug(double t) {cerr << t;}
void debug(unsigned ll t) {cerr << t;}
template <class Y, class V> void debug(pair <Y, V> p);
template <class Y> void debug(vector <Y> v);
template <class Y> void debug(set <Y> v);
template <class Y, class V> void debug(map <Y, V> v);
template <class Y> void debug(multiset <Y> v);
template <class Y, class V> void debug(pair <Y, V> p) {cerr << "{"; debug(p.ff); cerr << ","; debug(p.ss); cerr << "}";}
template <class Y> void debug(vector <Y> v) {cerr << "[ "; for (Y i : v) {debug(i); cerr << " ";} cerr << "]";}
template <class Y> void debug(set <Y> v) {cerr << "[ "; for (Y i : v) {debug(i); cerr << " ";} cerr << "]";}
template <class Y> void debug(multiset <Y> v) {cerr << "[ "; for (Y i : v) {debug(i); cerr << " ";} cerr << "]";}
template <class Y, class V> void debug(map <Y, V> v) {cerr << "[ "; for (auto i : v) {debug(i); cerr << " ";} cerr << "]";}
template <typename Head, typename... Tail> void debug(Head H, Tail... T){cerr << H << ' ';debug(T...);}
/*------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
#define endl '\n'
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define sz(x) (ll)x.size()
#define pqh priority_queue
#define ook order_of_key   //  returns position (unsigned integer) to given key
#define fbo find_by_order  //  returns iterator to the element at given position
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,n) for(i=1;i<=n;i++)
#define rep(i,a,b) for(i=a;i<=b;i++)
#define per(i,b,a) for(i=b;i>=a;i--)
#define all(x) x.begin(), x.end()
#define zerobits(x) __builtin_ctzll(x)
#define setbits(x)  __builtin_popcountll(x)
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define tol(s) transform(s.begin(),s.end(),s.begin(),::tolower);
#define tou(s) transform(s.begin(),s.end(),s.begin(),::toupper);
#define read(v) for(auto &itt:v) cin>>itt;
#define print(v) for(auto &itt:v) cout<<itt<<' ' ; cout<<endl;
#define T ll tt=0;cin>>tt;for(ll test=1;test<=tt;test++)
typedef pair<ll, ll>  pl;   typedef vector<pl>  vpl;    typedef pair<int,int> pi;    typedef vector<pi>   vpi;
typedef pair<ll,pl>   plp;  typedef vector<plp> vplp;   typedef pair<pi,int>  ppi;   typedef vector<ppi>  vppi;
typedef pair<pl,pl>   ppp;  typedef vector<ppp> vppp;   typedef pair<pi,pi>   pppi;  typedef vector<pppi>  vpppi;
typedef vector<ll>    vl;   typedef vector<vl>  vvl;    typedef vector<int>   vi;    typedef vector<vi>  vvi;
template <typename Y> using oset = tree<Y, null_type, less<Y>, rb_tree_tag, tree_order_statistics_node_update>;
template <class Y> void debug(oset<Y> v) {cerr << "[ "; for (auto i : v) {debug(i); cerr << " ";} cerr << "]";}
template <typename Y> using pql = priority_queue<Y, vector<Y>, greater<Y>>;
template <typename Y>
void make_unique(Y &vec) {
    vec.erase(unique(vec.begin(),vec.end()), vec.end());
}
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
ll randint(ll a, ll b){  return uniform_int_distribution<ll>(a, b)(rnd);   }
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
const ll mod = 1e9+7; //  998244353 ;
/*------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
ll isprime(ll n){ if(n<=1) return 0; if(n<=3) return 1; if(n%2==0||n%3==0) return 0; for(ll i=5;i*i<=n;i=i+6) if(n%i==0||n%(i+2)==0) return 0; return 1; } ll gcd(ll a,ll b){return __gcd(a,b); } void testnum(ll t){cout<<"Case #"<<t<<": ";}
ll lsb(ll n){ n=n^(n&(n-1)); ll pos=0; while(n){n=n>>1; pos++; } return pos-1; }/* acc. to zero indexing*/ ll bpow(ll a,ll n){ll res=1; while(n>0){ if(n&1LL) res=res*a; a=a*a; n>>=1; } return res; }
ll msb(ll n){                ll pos=0; while(n){n=n>>1; pos++; } return pos-1; }/* acc. to zero indexing*/ ll mpow(ll a, ll n,ll p){ a%=p; ll res=1; while(n>0){ if(n&1LL)res=res*a%p; a=a*a%p; n>>=1; } return res; }
ll add(ll a, ll b){ return (a+b)%mod; } ll sub(ll a,ll b){ return (a-b+mod)%mod; } ll mul(ll a, ll b){ return ((a%mod)* (b%mod)) % mod; } ll modI(ll n,ll p){ return mpow(n, p - 2, p); }
ll lcm(ll a,ll b){return (a*b)/__gcd(a,b);} ll LCM(vl &v,ll n){ ll ans=v[0]; for(ll i=1;i<n;i++) ans=(((v[i]*ans))/(__gcd(v[i],ans))); return ans; }ll ncr(ll n,ll r){if(n<0||r<0||n<r){return 0;}ll res=1;if(r>n-r)r=n-r;
for(ll i=0;i<r;++i){res*=(n-i);res/=(i+1);}return res; } map<ll, ll> pnt_compression(vl &pnt){ map<ll, ll> u; ll i=0,ct=0; fo(i,sz(pnt)){ u[pnt[i]]=0;} for(auto &it:u){ it.ss=ct; ct++;} return u; }
bool comp(pl a,pl b){ }
/*------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
const ld PI   = 3.141592653589793 ;
const ld eps  = 1e-9 ;
const ll inf  = 2e18 ; // 1e9;
const ll cons = 200005;
ll N,M;
ll solve(){ }
signed main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    #ifdef YuvrajSharma
    freopen("input.txt","r",stdin),freopen("output.txt","w",stdout),freopen("error.txt", "w", stderr);
    #endif
    // cout<<fixed<<setprecision(9);
    T{
        ll n=0,m=0,i=0,j=0,k=0,cnt=0,ans=0,sum=0,flag=0,pos=-1,ind=-1,mn=inf,mx=-inf,res=0;
        cin>>n>>m>>k;
        vl x(n),y(m);
        vpl v,h;
        vl a,b;
        read(x);
        read(y);
        fo(i,k){
            ll u1,v1;
            cin>>u1>>v1;
            if(binary_search(all(x),u1)&&binary_search(all(y),v1)){
                continue;
            }
            v.pb({u1,v1});
            if(binary_search(all(y),v1)) a.pb(v[i].ff);
            else b.pb(v[i].ss);
            h.pb({v1,u1});
        }
        sort(all(v));
        sort(all(h));
        sort(all(a));
        sort(all(b));
        fo(i,sz(v)){
            if(binary_search(all(x),v[i].ff)){
                auto it=lb(all(y),v[i].ss)-y.begin();
                it--;
                auto it2=lb(all(y),v[i].ss)-y.begin();
                ll z=lb(all(b),y[it2])-lb(all(b),y[it]);
                k=lb(all(v),pl(v[i].ff,y[it2]))-lb(all(v),pl(v[i].ff,y[it]));
                ans+=z-k;
            }
            else{
                auto it=lb(all(x),v[i].ff)-x.begin();
                it--;
                auto it2=lb(all(x),v[i].ff)-x.begin();
                ll z=lb(all(a),x[it2])-lb(all(a),x[it]);
                k=lb(all(h),pl(v[i].ss,x[it2]))-lb(all(h),pl(v[i].ss,x[it]));
                ans+=z-k;
            }
        }
        cout<<ans/2<<endl;




    }
    return 0;
}
/*  always remember these things
    => check edge cases like when n==1, l==r, overflow, array bounds
    => don't initialize dp with such values which dp state can attain
    => don't use memset when multiple testcases are present
    => there is a pattern when everything is uniformly distributed
    => try different approaches and try to find a general solution
    => BF, FC, LM, BS, MTH, GY, DP, DC, PSA, CT
*/
