1 const int mod = 9973;
2 LL Inverse[mod + 7];
3 Inverse[0] = 0, Inverse[1] = 1;
4 for(int i = 2; i < mod; i++)
5 Inverse[i] = ( - ( mod / i ) * Inverse[ mod % i ] ) % mod + mod;
1 const int maxN = 1000000 + 7;
2 const int p = 9973;
3 LL ni[p];
4 char str[maxN];
5 LL a[maxN];
6
7 int main(){
8 //freopen("input.txt", "r", stdin);
9 ni[1] = 1;
10 ni[0] = 0;
11 for(int i = 2; i < p; i++)
12 ni[i] = (-(p/i) * ni[p%i]) % p + p;
13 int n;
14 while(~scanf("%d", &n))
15 {
16 scanf("%s", str);
17 int len = strlen(str);
18 a[0] = 1;
19 for(int i = 1; i <= len; i++)
20 a[i] = a[i - 1] * (str[i - 1] - 28) % p;
21 while(n--){
22 int s, m;
23 scanf("%d%d", &s, &m);
24 printf("%I64d\n", a[m] * ni[a[s - 1]] % p);
25 }
26 }
27 return 0;
28 }