#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define ms(arr,a) memset(arr,a,sizeof arr)
#define debug(x) cout<<"< "#x" = "<<x<<" >"<<endl
const int maxn=1e6+5;
char s[maxn];
int n;
char c[2];
int main()
{
//freopen("Input.txt","r",stdin);
//freopen("Output.txt","w",stdout);
int T;scanf("%d",&T);
while(T--)
{
scanf("%d%s%s",&n,c,s);
int ans=n*2;
int i=0;
while(i<n&&s[i]==c[0]){ans=ans-2;i++;}
if(i==n){printf("1
");continue;}
int tmp=s[i]-c[0]>=0?s[i]-c[0]:c[0]-s[i];
if(tmp<10)ans--;
printf("%d
",ans);
}
//freopen("CON","w",stdout);
//system("start Output.txt");
}