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: import java.util.*;
  
  public class D {
  
  	public Object solve () {
  		sc.nextInt(); sc.nextInt();
  		int K = sc.nextInt();
  		int [] X = sc.nextInts(), Y = sc.nextInts();
  		int [][] P = sc.nextInts(K);
  
  		TreeSet<Integer> TX = new TreeSet<>(), TY = new TreeSet<>();
  		for (int x : X)
  			TX.add(x);
  		for (int y : Y)
  			TY.add(y);
  
  		Counter<Integer> CX = new Counter<>(), CY = new Counter<>();
  		Counter<Long> CX2 = new Counter<>(), CY2 = new Counter<>();
  
  		for (int [] p : P) {
  			int x = p[0], y = p[1];
  			int xx = TX.floor(x), yy = TY.floor(y);
  
  			if (xx < x) {
  				CX.inc(xx);
  				CX2.inc(1L * INF * y + xx);
  			}
  
  			if (yy < y) {
  				CY.inc(yy);
  				CY2.inc(1L * INF * x + yy);
  			}
  		}
  
  		long res = 0;
  
  		for (long c : CX.values())
  			res += c * c;
  		for (long c : CY.values())
  			res += c * c;
  
  		for (long c : CX2.values())
  			res -= c * c;
  		for (long c : CY2.values())
  			res -= c * c;
  
  		res /= 2;
  		return res;
  	}
  
  	private static final int CONTEST_TYPE = 2;
  
  	private static void init () {
  	}
  
  	private static final int INF = (int) 1e9 + 10;
  	////////////////////////////////////////////////////////////////////////////////////
  	private interface AbstractCounter<K> extends Map<K, Long> {
  		default AbstractCounter<K> inc (K key) { return inc(key, 1); }
  		default AbstractCounter<K> inc (K key, long value) { put(key, get(key) + value); return this; }
  		default AbstractCounter<K> incAll (K [] keys) { for (K key : keys) inc(key); return this; }
  	}
  	private static class Counter<K> extends TreeMap<K, Long> implements AbstractCounter<K> {
  		private static final long serialVersionUID = 1L;
  		public Counter (@SuppressWarnings("unchecked") K ... keys) { super(); incAll(keys); }
  		public Long get (Object key) {
  			Long res = super.get(key);
  			return res != null ? res : 0;
  		}
  		public Long put (K key, Long value) {
  			Long res;
  			if (value != 0)
  				res = super.put(key, value);
  			else
  				res = remove(key);
  			return res != null ? res : 0;
  		}
  	}
  	//////////////////////////////////////////////////////////////////////////////////// OFF
  	private static IOUtils.MyScanner sc = new IOUtils.MyScanner();
  	private static class IOUtils {
  		public static class MyScanner {
  			public String next () { newLine(); return line[index++]; }
  			public int nextInt () { return Integer.parseInt(next()); }
  			public String nextLine () { line = null; return readLine(); }
  			public String [] nextStrings () { return split(nextLine()); }
  			public int [] nextInts () {
  				String [] S = nextStrings(); int N = S.length;
  				int [] res = new int [N];
  				for (int i = 0; i < N; ++i)
  					res[i] = Integer.parseInt(S[i]);
  				return res;
  			}
  			public int [][] nextInts (int N) {
  				int [][] res = new int [N][];
  				for (int i = 0; i < N; ++i)
  					res[i] = nextInts();
  				return res;
  			}
  			//////////////////////////////////////////////
  			private boolean eol () { return index == line.length; }
  			private String readLine () {
  				try {
  					int b;
  					StringBuilder res = new StringBuilder();
  					while ((b = System.in.read()) < ' ')
  						continue;
  					res.append((char)b);
  					while ((b = System.in.read()) >= ' ')
  						res.append((char)b);
  					return res.toString();
  				} catch (Exception e) {
  					throw new Error (e);
  				}
  			}
  			private MyScanner () {
  				try {
  					while (System.in.available() == 0)
  						Thread.sleep(1);
  					start();
  				} catch (Exception e) {
  					throw new Error(e);
  				}
  			}
  			private String [] line;
  			private int index;
  			private void newLine () {
  				if (line == null || eol()) {
  					line = split(readLine());
  					index = 0;
  				}
  			}
  			private String [] split (String s) { return s.length() > 0 ? s.split(" ") : new String [0]; }
  		}
  		private static String build (Object o, Object ... A) { return buildDelim(" ", o, A); }
  		private static String buildDelim (String delim, Object o, Object ... A) {
  			java.util.List<String> str = new java.util.ArrayList<>();
  			append(str, o);
  			for (Object p : A)
  				append(str, p);
  			return String.join(delim, str.toArray(new String [0]));
  		}
  		//////////////////////////////////////////////////////////////////////////////////
  		private static java.text.DecimalFormat formatter = new java.text.DecimalFormat("#.#########");
  		private static void start () { if (t == 0) t = millis(); }
  		private static void append (java.util.function.Consumer<Object> f, java.util.function.Consumer<Object> g, Object o) {
  			if (o.getClass().isArray()) {
  				int len = java.lang.reflect.Array.getLength(o);
  				for (int i = 0; i < len; ++i)
  					f.accept(java.lang.reflect.Array.get(o, i));
  			}
  			else if (o instanceof Iterable<?>)
  				((Iterable<?>)o).forEach(f::accept);
  			else
  				g.accept(o instanceof Double ? formatter.format(o) : o);
  		}
  		private static void append (java.util.List<String> str, Object o) {
  			append(x -> append(str, x), x -> str.add(x.toString()), o);
  		}
  		private static java.io.PrintWriter pw = new java.io.PrintWriter(System.out);
  		private static void flush () { pw.flush(); System.out.flush(); }
  		private static void print (Object o, Object ... A) {
  			String res = build(o, A);
  			if (DEBUG == 2)
  				err(res, '(', time(), ')');
  			if (res.length() > 0)
  				pw.println(res);
  			if (DEBUG == 1)
  				flush();
  		}
  		private static void err (Object o, Object ... A) { System.err.println(build(o, A)); }
  		private static int DEBUG;
  		private static void exit () {
  			String end = "------------------" + System.lineSeparator() + time();
  			switch(DEBUG) {
  			case 1: print(end); break;
  			case 2: err(end); break;
  			}
  			IOUtils.pw.close();
  			System.out.flush();
  			System.exit(0);
  		}
  		private static long t;
  		private static long millis () { return System.currentTimeMillis(); }
  		private static String time () { return "Time: " + (millis() - t) / 1000.0; }
  		private static void run (int N) {
  			try { DEBUG = Integer.parseInt(System.getProperties().get("DEBUG").toString()); }
  			catch (Throwable t) {}
  
  			for (int n = 1; n <= N; ++n) {
  				Object res = new D().solve();
  				if (res != null) {
  					@SuppressWarnings("all")
  					Object o = CONTEST_TYPE == 0 ? "Case #" + n + ": " + build(res) : res;
  					print(o);
  				}
  			}
  			exit();
  		}
  	}
  	////////////////////////////////////////////////////////////////////////////////////
  	public static void main (String[] args) {
  		@SuppressWarnings("all")
  		int N = CONTEST_TYPE == 1 ? 1 : sc.nextInt();
  		init();
  		IOUtils.run(N);
  	}
  }
  