//Relive your past life. //Face your demons. //The past is never dead,it is not even past. //The memories are not only the key to the past but...also to the future. //coded in Rusty Lake #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define ll long long #define pb push_back #define mp make_pair #define orz 1000000007 using namespace std; int T,n,q,f[100005][30]; int main(){ scanf("%d",&T); for(int _=1;_<=T;++_){ printf("Case #%d:\n",_); scanf("%d%d",&n,&q); for(int i=1;i<=n;++i){ char c=getchar(); while(c<65)c=getchar(); int x=c-65; for(int j=0;j<26;++j)f[i][j]=f[i-1][j]; ++f[i][x]; } for(int i=1;i<=q;++i){ int l,r; scanf("%d%d",&l,&r); --l; for(int j=0;j<26;++j){ if(f[r][j]-f[l][j]){ printf("%d\n",f[r][j]-f[l][j]); break; } } } } //system("pause"); return 0; }