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.
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;

public class Main {
	static final long MOD=1000000007;
	static final long MOD1=998244353;
	static long ans=0;
	//static ArrayList<Integer> ans=new ArrayList<>();
	public static void main(String[] args){
		PrintWriter out = new PrintWriter(System.out);
		InputReader sc=new InputReader(System.in);
		int t = sc.nextInt();
		for (int i = 0; i < t; i++) {
			int n = sc.nextInt();
			int m = sc.nextInt();
			int k = sc.nextInt();
			int[] yline = sc.nextIntArray(n);
			int[] xline = sc.nextIntArray(m);
			int[] px = new int[k];
			int[] py = new int[k];
			for (int j = 0; j < py.length; j++) {
				px[j] = sc.nextInt();
				py[j] = sc.nextInt();
			}
			out.println(solve(n, m, k, yline, xline, px, py));
		}
		out.flush();
	}
	static long solve(int n,int m,int k,int[] yline,int[] xline,int[] px,int[] py) {
		HashSet<Integer> yset = new HashSet<Integer>();
		HashSet<Integer> xset = new HashSet<Integer>();
		ArrayList<Pair> xlist = new ArrayList<Main.Pair>();
		ArrayList<Pair> ylist = new ArrayList<Main.Pair>();
		for (int i = 0; i < n; i++) {
			yset.add(yline[i]);
			xlist.add(new Pair(yline[i], -1));
		}
		for (int i = 0; i < m; i++) {
			xset.add(xline[i]);
			ylist.add(new Pair(xline[i], -1));
		}
		for (int i = 0; i < k; i++) {
			boolean xx = xset.contains(py[i]);
			boolean yy = yset.contains(px[i]);
			if(xx&&yy)continue;
			if (xx)xlist.add(new Pair(px[i], py[i]));
			if (yy)ylist.add(new Pair(py[i], px[i]));
		}
		Collections.sort(xlist);
		Collections.sort(ylist);
		HashMap<Integer, Long> mapx = new HashMap<Integer, Long>();
		HashMap<Integer, Long> mapy = new HashMap<Integer, Long>();
		long sumx = 0;
		long sumy = 0;
		long ans = 0;
		for (int i = 0; i < xlist.size(); i++) {
			Pair p = xlist.get(i);
			if (p.y==-1) {
				mapx.clear();
				sumx=0;
			}else {
				ans += sumx;
				if (mapx.containsKey(p.y)) {
					ans -= mapx.get(p.y);
				}else {
					mapx.put(p.y, 0l);
				}
				mapx.put(p.y, mapx.get(p.y)+1l);
				sumx++;
			}
		}
		for (int i = 0; i < ylist.size(); i++) {
			Pair p = ylist.get(i);
			if (p.y==-1) {
				mapy.clear();
				sumy=0;
			}else {
				ans += sumy;
				if (mapy.containsKey(p.y)) {
					ans -= mapy.get(p.y);
				}else {
					mapy.put(p.y, 0l);
				}
				mapy.put(p.y, mapy.get(p.y)+1l);
				sumy++;
			}
		}
		return ans;
	}
	static class Pair implements Comparable<Pair>{
    	public int x;
    	public int y;
    	public Pair(int x,int y) {
    		this.x=x;
    		this.y=y;
    	}
    	@Override
    	public boolean equals(Object obj) {
    		if(obj instanceof Pair) {
    			Pair other = (Pair) obj;
    			return other.x==this.x && other.y==this.y;
    		}
    		return false;
    	}//同値の定義
    	@Override
    	public int hashCode() {
    		return Objects.hash(this.x,this.y);
    	}//これ書かないと正しく動作しない（要　勉強）
    	@Override
    	public int compareTo( Pair p){
    		if (this.x>p.x) {
    			return 1;
    		}
    		else if (this.x<p.x) {
    			return -1;
    		}
    		else {
    			return 0;
    		}
    	}
    }
	static class InputReader { 
		private InputStream in;
		private byte[] buffer = new byte[1024];
		private int curbuf;
		private int lenbuf;
		public InputReader(InputStream in) {
			this.in = in;
			this.curbuf = this.lenbuf = 0;
		}
		public boolean hasNextByte() {
			if (curbuf >= lenbuf) {
				curbuf = 0;
				try {
					lenbuf = in.read(buffer);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (lenbuf <= 0)
					return false;
			}
			return true;
		}
 
		private int readByte() {
			if (hasNextByte())
				return buffer[curbuf++];
			else
				return -1;
		}
 
		private boolean isSpaceChar(int c) {
			return !(c >= 33 && c <= 126);
		}
 
		private void skip() {
			while (hasNextByte() && isSpaceChar(buffer[curbuf]))
				curbuf++;
		}
 
		public boolean hasNext() {
			skip();
			return hasNextByte();
		}
 
		public String next() {
			if (!hasNext())
				throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while (!isSpaceChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}
 
		public int nextInt() {
			if (!hasNext())
				throw new NoSuchElementException();
			int c = readByte();
			while (isSpaceChar(c))
				c = readByte();
			boolean minus = false;
			if (c == '-') {
				minus = true;
				c = readByte();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res = res * 10 + c - '0';
				c = readByte();
			} while (!isSpaceChar(c));
			return (minus) ? -res : res;
		}
 
		public long nextLong() {
			if (!hasNext())
				throw new NoSuchElementException();
			int c = readByte();
			while (isSpaceChar(c))
				c = readByte();
			boolean minus = false;
			if (c == '-') {
				minus = true;
				c = readByte();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res = res * 10 + c - '0';
				c = readByte();
			} while (!isSpaceChar(c));
			return (minus) ? -res : res;
		}
 
		public double nextDouble() {
			return Double.parseDouble(next());
		}
 
		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}
		public double[] nextDoubleArray(int n) {
			double[] a = new double[n];
			for (int i = 0; i < n; i++)
				a[i] = nextDouble();
			return a;
		}
		public long[] nextLongArray(int n) {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextLong();
			return a;
		}
 
		public char[][] nextCharMap(int n, int m) {
			char[][] map = new char[n][m];
			for (int i = 0; i < n; i++)
				map[i] = next().toCharArray();
			return map;
		}
	}
}
