#include #include #include #include #define maxn 100010 #define mo 9973 using namespace std; int n, l, r, q, h[maxn], inv[maxn]; char s[maxn]; int main() { inv[1] = 1; for (int i = 2; i < mo; ++ i) inv[i] = (mo - 1ll * (mo / i) * inv[mo % i] % mo) % mo; while (scanf("%d", &q) == 1){ scanf("%s", s + 1); n = strlen(s + 1); h[0] = 1; for (int i = 1; i <= n; ++ i) h[i] = 1ll * h[i - 1] * (s[i] - 28) % mo; while (q --){ scanf("%d%d", &l, &r); printf("%I64d\n", 1ll * h[r] * inv[h[l - 1]] % mo); } } }