#include <bits/stdc++.h>
using namespace std;
int T,n,k,d,t;
int A[1005];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> T;
while(T--)
{
d = 0;
cin >> n >> k;
for(int i = 1; i <= n; i++)
{
cin >> A[i];
if (A[i] == k) d++;
while(A[i] > 0)
{
t = A[i] % 10;
A[i] /= 10;
if(t == k) d++;
}
}
cout << d << endl;
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwppbnQgVCxuLGssZCx0OwppbnQgQVsxMDA1XTsKaW50IG1haW4oKSB7CiAgICBpb3NfYmFzZTo6c3luY193aXRoX3N0ZGlvKGZhbHNlKTsKICAgIGNpbi50aWUoTlVMTCk7CiAgICBjaW4gPj4gVDsKICAgIHdoaWxlKFQtLSkKICAgIHsKICAgICAgICBkID0gMDsKICAgICAgICBjaW4gPj4gbiA+PiBrOwogICAgICAgIGZvcihpbnQgaSA9IDE7IGkgPD0gbjsgaSsrKQogICAgICAgIHsKICAgICAgICAgICAgY2luID4+IEFbaV07CiAgICAgICAgICAgIGlmIChBW2ldID09IGspIGQrKzsKICAgICAgICAgICAgd2hpbGUoQVtpXSA+IDApCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIHQgPSBBW2ldICUgMTA7CiAgICAgICAgICAgICAgICBBW2ldIC89IDEwOwogICAgICAgICAgICAgICAgaWYodCA9PSBrKSBkKys7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgY291dCA8PCBkIDw8IGVuZGw7CiAgICB9CiAgICByZXR1cm4gMDsKfQ==