#include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair PII; #define fi first #define se second #define MP make_pair int read() { int v = 0, f = 1; char c = getchar(); while (c < 48 || 57 < c) {if (c == '-') f = -1; c = getchar();} while (48 <= c && c <= 57) v = (v << 3) + v + v + c - 48, c = getchar(); return v * f; } const int MOD = 9973; char ch[1000000]; int pw(int a, int b) { int re = 1; while (b) { if (b & 1) re = re * a % MOD; a = a * a % MOD; b >>= 1; } return re; } int ha[1000000]; void Main() { int n, q; while (~scanf("%d", &q)) { scanf("%s", ch + 1); n = strlen(ch + 1); ha[0] = 1; for (int i = 1; i <= n; i++) ha[i] = ha[i - 1] * (ch[i] - 28) % MOD; while (q--) { int u, v; scanf("%d%d", &u, &v); printf("%d\n", ha[v] * pw(ha[u - 1], MOD - 2) % MOD); } } } int main() { Main(); }