#include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; int inv_t[10010]; void inv_table(int n, int mod) { inv_t[1] = 1; for(int i = 2; i < n; ++i) inv_t[i] = (mod - 1LL * (mod / i) * inv_t[mod % i] % mod) % mod; } int a[100010], n; char s[100010] = {}; int query(int x) { int ret = 1; for(; x >= 1; x -= x & -x) ret = ret * a[x] % 9973; return ret; } int main() { inv_table(9973, 9973); while(scanf("%d", &n) == 1) { scanf("%s", s + 1); const int l = strlen(s + 1); fill(a + 1, a + 1 + l, 1); for(int i = 1; i <= l; ++i) { const int v = s[i] - 28; for(int j = i; j <= l; j += j & -j) a[j] = a[j] * v % 9973; } while(n--) { int ql, qr; scanf("%d%d", &ql, &qr); int ans = query(qr) * inv_t[query(ql-1)] % 9973; printf("%d\n", ans); } } return 0; }