#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define F1(x,y,z) for(int x=y;xz;x--) #define F4(x,y,z) for(int x=y;x>=z;x--) #define pb push_back #define LL long long #define co complex #define MAX 100005 #define AMAX 1500 #define MOD 1000000007 #define f(c,d) ((1<<(c))*(d)) using namespace std; int q,i,ta,tb,y[MAX],inv[9973]; char x[MAX]; int po(int b,int p){ if(p==0)return 1; if(p&1)return b*po(b,p-1)%9973; int tt=po(b,p/2); return tt*tt%9973; } int main(){ y[0]=1; F1(a,1,9973)inv[a]=po(a,9973-2); while(scanf("%d",&q)==1){ i=0; scanf("%s",x); while(x[i]){ y[i+1]=y[i]*(x[i]-28)%9973; x[i++]=0; } while(q--){ scanf("%d%d",&ta,&tb); printf("%d\n",y[tb]*inv[y[ta-1]]%9973); } } //system("pause"); return 0; }