#include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define getmid(l,r) ((l) + ((r) - (l)) / 2) #define MEM(a,b) memset(a,b,sizeof(a)) #define MP(a,b) make_pair(a,b) #define PB push_back typedef long long ll; typedef pair pii; const double eps = 1e-8; const int INF = (1 << 30) - 1; const int mod = 9973; int N; char s[100010]; int pre[100010]; int Q_pow(int x,int y){ int res = 1; while(y){ if(y & 1) res = res * x % mod; x = x * x % mod; y >>= 1; } return res; } int main(){ while(scanf("%d",&N) != EOF){ scanf("%s",s + 1); pre[0] = 1; for(int i = 1; s[i]; ++i){ pre[i] = pre[i - 1] * (s[i] - 28) % mod; } for(int i = 1; i <= N; ++i){ int a,b; scanf("%d%d",&a,&b); printf("%d\n",pre[b] * Q_pow(pre[a - 1],mod - 2) % mod); } } return 0; }