#include #include #include #include #include #include #include #include using namespace std; typedef long long LL; int T,len,num,j; LL ans; char s[1000005]; int a[30]; int k; int main() { scanf("%d",&T); while (T--) { scanf("%s",s+1); len=strlen(s+1); scanf("%d",&k); num=0;j=0;ans=0; memset(a,0,sizeof(a)); for (int i=1;i<=len;++i) { while (num