description: 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.
solution: 
  def naiveSolve():
      
      
      
      return
  
  
  
  def solve():
      
      
      
      return
  
  class SegmentTree():
      def __init__(self,arr,combinerFunction,isCommutative=True): # isCommutative means f(a,b)==f(b,a)
          self.n=len(arr)
          def cmb(a,b):
              if a==None: return b
              if b==None: return a
              return combinerFunction(a,b)
          self.cmb=cmb
          self.sz=self.n if isCommutative else pow(2,((self.n-1).bit_length())) # non-commutative needs power of 2 size
          self.t=[None]*(2*self.sz) # use None as initial value
          for i in range(self.n): self.t[i+self.sz]=arr[i]
          for i in range(self.sz-1,0,-1): self.pull(i)
      def pull(self,p):
          self.t[p]=self.cmb(self.t[2*p],self.t[2*p+1])
      def update(self,idx,val): # set val at idx
          idx+=self.sz
          self.t[idx]=val
          idx//=2
          while idx>0:
              self.pull(idx)
              idx//=2
      def query(self,l,r): # aggregated value in [l,r] inclusive
          l+=self.sz; r+=self.sz+1
          a=b=None
          while l<r:
              if l%2==1: a=self.cmb(a,self.t[l]); l+=1
              if r%2==1: r-=1; b=self.cmb(self.t[r],b)
              l//=2; r//=2
          return self.cmb(a,b)
  def getMaxSegTree(arr):
      return SegmentTree(arr,lambda a,b:max(a,b),False)
  def getMinSegTree(arr):
      return SegmentTree(arr,lambda a,b:min(a,b),False)
  def getSumSegTree(arr):
      return SegmentTree(arr,lambda a,b:a+b,False)
  
  from collections import defaultdict
  
  def countHorizontal(xes,onX): # return how many bad pairs for points on horizontal lines
      # print('xes:{} onX:{}'.format(xes, onX))    
      # coordinate compress all y-values
      xSet=set(xes)
      for x,y in onX: xSet.add(x)
      xSorted=sorted(xSet)
      N=len(xSorted)
      xMap={x:i for i,x in enumerate(xSorted)}
      for i,x in enumerate(xes): xes[i]=xMap[x]
      for i,[x,y] in enumerate(onX): onX[i][0]=xMap[x]
      
      yItems=defaultdict(list) # {y:[x1,x2,x3,...]}
      for x,y in onX: yItems[y].append(x)
      for v in yItems.values(): v.sort()
      
      # print('onX:{} xes:{} xSorted:{}'.format(onX, xes, xSorted))
      
      segArr=[0]*(N+1)
      for x,y in onX: segArr[x]+=1
      st=getSumSegTree(segArr)
      
      cnts=0
      for x,y in onX:
          i=-1
          bb=len(xes)
          while bb>0:
              while i+bb<len(xes) and xes[i+bb]<x:
                  i+=bb
              bb//=2
          left=xes[i]+1
          right=xes[i+1]-1 # there should be no line on x, so the next 1 is an index ahead
          # print('left:{} right:{}'.format(left,right))
          include=st.query(left,right)
          
          # remove those on the same line
          arr=yItems[y]
          i=-1
          bb=len(arr)
          while bb>0:
              while i+bb<len(arr) and arr[i+bb]<left:
                  i+=bb
              bb//=2
          left2=i+1
          i=-1
          bb=len(arr)
          while bb>0:
              while i+bb<len(arr) and arr[i+bb]<=right:
                  i+=bb
              bb//=2
          right2=i
          exclude=right2-left2+1
          
          cnts+=include-exclude
      return cnts
      
  
  def main():
      
      # only some x->x and y->y pairs cannot
      # pad all roads xes and yes by 1
      # must coordinate compress because of segment trees
      
      t=int(input())
      allans=[]
      for _ in range(t):
          n,m,k=readIntArr()
          xes=[-1]+readIntArr()+[1000001] # vertical streets, sorted already
          yes=[-1]+readIntArr()+[1000001] # horizontal streets, sorted already
          
          xSet=set(xes)
          ySet=set(yes)
          onX=[]; onY=[]; onXandY=[] # (x,y)
          for __ in range(k):
              x,y=readIntArr()
              isOnX=x in xSet
              isOnY=y in ySet
              if isOnX and isOnY:
                  onXandY.append((x,y))
              elif isOnX and not isOnY:
                  onX.append([x,y])
              else:
                  onY.append([x,y])
          xN=len(onX); yN=len(onY); xyN=len(onXandY)
          assert xN+yN+xyN==k
          # print('xN:{} yN:{} xyN:{}'.format(xN,yN,xyN))
          
          # find all pairs first then divide by 2 later
          ans=0
          ans+=countHorizontal(xes,onY) # for items on horizontal lines
          # swap x and y for onX and do the same
          onX2=[[y,x] for x,y in onX]
          ans+=countHorizontal(yes,onX2)
          
          ans//=2
          allans.append(ans)
          
      multiLineArrayPrint(allans)
      
      return
  
  
  
  
  import sys
  input=sys.stdin.buffer.readline #FOR READING PURE INTEGER INPUTS (space separation ok)
  # input=lambda: sys.stdin.readline().rstrip("\r\n") #FOR READING STRING/TEXT INPUTS.
  
  def oneLineArrayPrint(arr):
      print(' '.join([str(x) for x in arr]))
  def multiLineArrayPrint(arr):
      print('\n'.join([str(x) for x in arr]))
  def multiLineArrayOfArraysPrint(arr):
      print('\n'.join([' '.join([str(x) for x in y]) for y in arr]))
   
  def readIntArr():
      return [int(x) for x in input().split()]
  # def readFloatArr():
  #     return [float(x) for x in input().split()]
   
  def makeArr(defaultValFactory,dimensionArr): # eg. makeArr(lambda:0,[n,m])
      dv=defaultValFactory;da=dimensionArr
      if len(da)==1:return [dv() for _ in range(da[0])]
      else:return [makeArr(dv,da[1:]) for _ in range(da[0])]
   
  def queryInteractive(x):
      print('{}'.format(x))
      sys.stdout.flush()
      return int(input())
   
  def answerInteractive(ans):
      print('! {}'.format(ans))
      sys.stdout.flush()
   
  inf=float('inf')
  # MOD=10**9+7
  # MOD=998244353
  
  from math import gcd,floor,ceil
  # from math import floor,ceil # for Python2
   
  for _abc in range(1):
      main()