#include #include #include using namespace std; #define LL long long char map[105000]; LL dp[105000]; void jj(LL n) { dp[0]=1; for(LL i=1;i<=n;i++) { dp[i]=(dp[i-1]*(map[i-1]-28))%9973; } } //3Ë・¨μÄÄæÔa LL quickmod(LL a,LL b) { LL sum=1; while(b) { if(b&1) sum=(sum*a)%9973; b>>=1; a=(a*a)%9973; } return sum; } int main() { LL t; while(scanf("%lld",&t)!=EOF) { scanf("%s",map); LL len=strlen(map); jj(len); while(t--) { LL r,l; scanf("%lld%lld",&r,&l); //printf("%d %d\n",dp[r-1],dp[l]); if(r>l) { swap(r,l); } printf("%lld\n",(dp[l]*quickmod(dp[r-1],9973-2))%9973); } } return 0; }