#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")
# include <iostream>
# include <algorithm>
using namespace std;
int a[101010];
int b[101010];
int main() {
ios_base::sync_with_stdio(0);cin.tie(0);
int tc;
cin >> tc;
for (int cs = 1; cs <= tc; ++cs) {
cout << "Case #" << cs << ": ";
int n, k;
cin >> n >> k;
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
for (int i = 0; i < n; ++i) {
cin >> b[i];
}
long long ans = 0;
for (int i = n - 1; i >= 0; --i) {
int whereA = int(std::lower_bound(a + i + 1, a + n, a[i]) - a);
int x = a[i];
for (int j = i; j < whereA; ++j) {
a[j] = x;
}
int whereB = int(std::lower_bound(b + i + 1, b + n, b[i]) - b);
x = b[i];
for (int j = i; j < whereB; ++j) {
b[j] = x;
}
for (int j = i; j < n; ++j) {
ans += abs(a[j] - b[j]) <= k;
}
}
cout << ans << endl;
}
return 0;
}
I3ByYWdtYSBHQ0Mgb3B0aW1pemUoIk9mYXN0IikKI3ByYWdtYSBHQ0MgdGFyZ2V0KCJzc2Usc3NlMixzc2UzLHNzc2UzLHNzZTQsYXZ4LGF2eDIiKQoKIyBpbmNsdWRlIDxpb3N0cmVhbT4KIyBpbmNsdWRlIDxhbGdvcml0aG0+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgYVsxMDEwMTBdOwppbnQgYlsxMDEwMTBdOwoKaW50IG1haW4oKSB7CiAgICBpb3NfYmFzZTo6c3luY193aXRoX3N0ZGlvKDApO2Npbi50aWUoMCk7CiAgICBpbnQgdGM7CiAgICBjaW4gPj4gdGM7CiAgICBmb3IgKGludCBjcyA9IDE7IGNzIDw9IHRjOyArK2NzKSB7CiAgICAgICAgY291dCA8PCAiQ2FzZSAjIiA8PCBjcyA8PCAiOiAiOwogICAgICAgIGludCBuLCBrOwogICAgICAgIGNpbiA+PiBuID4+IGs7CiAgICAgICAgZm9yIChpbnQgaSA9IDA7IGkgPCBuOyArK2kpIHsKICAgICAgICAJY2luID4+IGFbaV07CiAgICAgICAgfQogICAgICAgIGZvciAoaW50IGkgPSAwOyBpIDwgbjsgKytpKSB7CiAgICAgICAgCWNpbiA+PiBiW2ldOwogICAgICAgIH0KICAgICAgICBsb25nIGxvbmcgYW5zID0gMDsKICAgICAgICBmb3IgKGludCBpID0gbiAtIDE7IGkgPj0gMDsgLS1pKSB7CiAgICAgICAgICAgIGludCB3aGVyZUEgPSBpbnQoc3RkOjpsb3dlcl9ib3VuZChhICsgaSArIDEsIGEgKyBuLCBhW2ldKSAtIGEpOwogICAgICAgICAgICBpbnQgeCA9IGFbaV07CiAgICAgICAgICAgIGZvciAoaW50IGogPSBpOyBqIDwgd2hlcmVBOyArK2opIHsKICAgICAgICAgICAgICAgIGFbal0gPSB4OwogICAgICAgICAgICB9CiAgICAgICAgICAgIGludCB3aGVyZUIgPSBpbnQoc3RkOjpsb3dlcl9ib3VuZChiICsgaSArIDEsIGIgKyBuLCBiW2ldKSAtIGIpOwogICAgICAgICAgICB4ID0gYltpXTsKICAgICAgICAgICAgZm9yIChpbnQgaiA9IGk7IGogPCB3aGVyZUI7ICsraikgewogICAgICAgICAgICAgICAgYltqXSA9IHg7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgZm9yIChpbnQgaiA9IGk7IGogPCBuOyArK2opIHsKICAgICAgICAgICAgICAgIGFucyArPSBhYnMoYVtqXSAtIGJbal0pIDw9IGs7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgY291dCA8PCBhbnMgPDwgZW5kbDsKICAgIH0KICAgIHJldHVybiAwOwp9Cg==