/*Sherlock and Watson and Adler*/ #pragma comment(linker, "/STACK:1024000000,1024000000") #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define exp 1e-10 #define ll long long using namespace std; const int N = 1000007; const int M = 10000 + 10; const int inf = 100000000; const int mod = 2009; char s[N]; int vit[30]; int main() { int t,m,k,p,i,j,len,tmp; long long sum; int n; scanf("%d",&t); while(t--) { memset(vit,0,sizeof(vit)); scanf("%s%d",s,&n); len=strlen(s); sum=tmp=p=0; for(i=0;i= n) { sum = sum + len - i ; for(j=p;j