#include <iostream>
#include <string.h>
#include <cmath>
using namespace std;
const int N=1000000;
int main()
{
int t;
char z;
int n, num;
string s;
cin >> t;
while(t--){
cin >> n >> z;
int val=0;
cin >> s;
for(int i=0; i<n; i++){
if(abs(z-s[i])){
val = (n-i)*2;
if(abs(z-s[i])<10)
val--;
break;
}
}
if(val)
cout << val << endl;
else cout << "1" << endl;
}
return 0;
}
//比较坑的就是为零的时候位数为1
#include <iostream>
#include <cmath>
#include <stdlib.h>
#include <algorithm>
#include <string.h>
using namespace std;
int main()
{
int T, n;
cin >> T;
char c, temp;
while(T--)
{
cin >> n >> c;
int cnt = 0, flag = 0;
for(int i=0; i<n; i++)
{
cin >> temp;
// cout << abs(c-temp) << endl;
if(abs(c-temp)>9)
{
cnt += 2;
flag = 1;
}
else if(abs(c-temp)> 0)
{if(flag)
cnt += 2;
else {cnt ++;flag = 1;}
}
else if(flag)
cnt += 2;
}
if(cnt == 0) cout << "1" << endl;
else
cout << cnt << endl;
}
return 0;
}