#include #include #include #include #include #include #include using namespace std; const int Maxn=100005,P=9973; int Q,n; char s[Maxn]; int a[Maxn],b[Maxn]; int Pow(int x,int y) { int tmp=1; while(y) { if (y&1) tmp=tmp*x%P; x=x*x%P; y>>=1; } return tmp; } int main() { //freopen(".in","r",stdin); //freopen(".out","w",stdout); int i,j,x,y; while(scanf ("%d",&Q)!=EOF) { scanf (" %s",s+1);n=strlen(s+1); a[0]=1;for (i=1;i<=n;i++) a[i]=a[i-1]*(s[i]-28)%P; b[n]=Pow(a[n],P-2);for (i=n-1;i>=0;i--) b[i]=b[i+1]*(s[i+1]-28)%P; for (i=1;i<=Q;i++) scanf ("%d%d",&x,&y),printf ("%d\n",a[y]*b[x-1]%P); } return 0; }