#include #include const int maxn = 100005; const int mod = 9973; int n, l; char ch[maxn]; int c[maxn]; typedef long long ll; void exgcd(int a, int b, ll &d, ll &x, ll &y) { if (!b) { d = a; x = 1; y = 0; } else { exgcd(b, a % b, d, y, x); y -= x * (a / b); } } ll inv(int a) { ll d, x, y; exgcd(a, mod, d, x, y); return (x + mod) % mod; } int main() { while (scanf("%d", &n) == 1) { scanf("%s", ch); l = strlen(ch); c[0] = 1; for (int i = 1; i <= l; i++) c[i] = c[i - 1] * (ch[i - 1] - 28) % mod; while (n--) { int a, b; scanf("%d%d", &a, &b); printf("%d\n", int(c[b] * inv(c[a - 1]) % mod)); } } return 0; }