#include #include #include #define ls t<<1 #define rs (t<<1)|1 using namespace::std; const int MOD = 9973; const int maxn = 1e5 + 10; int fa[maxn], n, x, y; char str[maxn]; struct Node { int val, l, r; }tree[maxn * 4]; void Build(int l, int r, int t) { tree[t].l = l; tree[t].r = r; tree[t].val = 0; if (l == r) { fa[l] = t; return; } Build(l, (l + r) / 2, ls); Build((l + r) / 2 + 1, r, rs); } void Update(int t) { if (t == 1) return; t /= 2; tree[t].val = (tree[ls].val * tree[rs].val) % MOD; Update(t); } int Query(int l, int r, int t) { int sum = 1; if (tree[t].l >= l && tree[t].r <= r) return tree[t].val; int mid = (tree[t].l + tree[t].r) / 2; if (l <= mid) sum = (sum * Query(l, r, ls)) % MOD; if (r > mid) sum = (sum * Query(l, r, rs)) % MOD; return sum; } int main() { while (~scanf("%d", &n)) { scanf("%s", str); int len = strlen(str); Build(1, len, 1); for (int i = 1; i <= len; i++) { tree[fa[i]].val = str[i - 1] - 28; Update(fa[i]); } int tmp; for (int i = 0; i < n; i++) { scanf("%d%d", &x, &y); if (x <= len && y <= len) { if (x > y) swap(x, y); tmp = Query(x, y, 1); } printf("%d\n", tmp); } } return 0; }