ll Pow(ll x, ll y){ ll res = 1; while (y--) res *= x; return res; }
intcount(ll a[], int n, ll V){ ll sum = 0; int r = 0, ans = 0; for (int l = 0; l < n; l++) { r = max(r, l);
while (r < n && sum + a[r] <= V) { sum += a[r]; r++; } ans += r - l; if (r > l) sum -= a[l]; } return ans; }
constint maxn = 1003; int x[maxn], y[maxn]; ll diff[maxn][maxn],diag[maxn];
intabs_(int x){ return x > 0 ? x : -x; } intmain(){ int T; scanf("%d", &T); while (T--) { int n, p; ll V; scanf("%d%lld%d", &n, &V, &p); for (int i = 0; i < n; i++) scanf("%d", x + i); for (int i = 0; i < n; i++) scanf("%d", y + i); for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) diff[i][j] = Pow(abs_(x[i] - y[j]), p); int ans = 0; for (int i = 0; i < n; i++) { int di = 0; for (int xi = 0, yi = i; xi < n && yi < n; xi++, yi++) diag[di++] = diff[xi][yi]; ans += count(diag, di, V); } for (int i = 1; i < n; i++) { int di = 0; for (int xi = i, yi = 0; xi < n && yi < n; xi++, yi++) diag[di++] = diff[xi][yi]; ans += count(diag, di, V); } printf("%d\n",ans); } }