#include #include #include #include using namespace std; const int mod = 9973; const int maxn = 102400; int N, len, L, R; int mul[maxn]; char s[maxn]; int quickpow(int m, int n, int k) { int res = 1, base = m; while(n > 0) { if(n & 1) res = (res * base) % k; base = (base * base) % k; n >>= 1; } return res % k; } int divMod(int a, int b, int mod) { return a * quickpow(b, mod-2, mod) % mod; } int main() { while(~scanf("%d", &N)) { scanf("%s", s + 1); len = strlen(s + 1); mul[0] = 1; for(int i = 1; i <= len; ++i) mul[i] = (mul[i-1] * (s[i] - 28)) % mod; for(int i = 1; i <= N; ++i) { scanf("%d%d", &L, &R); int ans = divMod(mul[R], mul[L-1], mod); printf("%d\n", ans); } } return 0; }