#include #include #include using namespace std; const int mod = 9973, mlen = 1e5 + 10; char str[mlen]; int hash[mlen], inver[mlen]; int pow(int d, int m) { int ans = 1; while (m) { if (m & 1) (ans *= d) %= mod; (d *= d) %= mod; m >>= 1; } return ans; } int main() { hash[0] = inver[0] = 1; int n; while(scanf("%d", &n) != EOF) { scanf("%s", str + 1); for (int i = 1 ; str[i] ; i++) { hash[i] = hash[i - 1] * (str[i] - 28) % mod; inver[i] = pow(hash[i], mod - 2); } while (n--) { int l, r; scanf("%d%d", &l, &r); printf("%d\n", hash[r] * inver[l - 1] % mod); } } return 0; }