import java.io.*;
import java.util.Arrays;
import static java.lang.Math.abs;
public class Solution {
public static void main(String[] args) throws IOException {
in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
int T = nextInt();
for (int tc = 1; tc <= T; tc++) {
readCase();
work();
System.out.println("#" + tc + " " + ans1 + " " + ans2);
}
}
static void work() {
Arrays.sort(d, 0, N);
ans1 = 0;
ans2 = 0;
for (int i = 0; i < M; i++) {
if (abs(p[1][i]) > D) continue;
if (abs(p[1][i]) == D) {
int pos = Arrays.binarySearch(d, 0, N, p[0][i]);
if (pos >= 0) {
ans1++;
ans2++;
}
} else {
int len = D - abs(p[1][i]);
int pos1 = Arrays.binarySearch(d, 0, N, p[0][i] + len);
int pos2 = Arrays.binarySearch(d, 0, N, p[0][i] - len);
if (pos1 == pos2) continue;//两点间无商铺
if (pos1 < 0 && pos2 >= 0) {
pos1 = abs(pos1 + 1);
if (pos1 < pos2) pos1--;
} else if (pos1 >= 0 && pos2 < 0) {
pos2 = abs(pos2 + 1);
if (pos2 < pos1) pos2--;
} else {
pos1 = abs(pos1 + 1);
pos2 = abs(pos2 + 1);
}
ans1++;
ans2 += abs(pos1 - pos2);
}
}
}
static void readCase() throws IOException {
N = nextInt();
M = nextInt();
D = nextInt();
for (int i = 0; i < N; i++) d[i] = nextInt();
for (int i = 0; i < M; i++) {
p[0][i] = nextInt();//x
p[1][i] = nextInt();//y
}
}
static int nextInt() throws IOException {
in.nextToken();
return (int) in.nval;
}
static StreamTokenizer in;
static int N, M, D, ans1, ans2;
static final int[] d = new int[100003];
static final int[][] p = new int[2][100003];
}
3
4 3 3
-4 4 1 0
0 2
-3 -1
3 -3
1 1 1
1
2 0
1 1 1
1
2 1
#1 2 3
#2 1 1
#3 0 0