char t[];main(x,l,a,i,L){for(;~scanf("%d%s",&i,t);)for(L=l=strlen(t);x=++i,~l;putchar(l--?a:10))for(a=i=0;x-=a==t[i];a+=!i)i=++i%L;}