#include #include using namespace std; const int maxn = 100000 + 10; #define lson (rt << 1) #define rson (rt << 1 | 1) #define MOD 9973 typedef struct{ int l, r; int val; }Tree; int cur, len, ans; char str[maxn]; Tree t[maxn << 2]; void build(int rt, int l, int r){ t[rt].l = l; t[rt].r = r; if(l == r){ t[rt].val = str[cur++] - 28; return; } int mid = (l + r) >> 1; build(lson, l, mid); build(rson, mid + 1, r); t[rt].val = (t[lson].val * t[rson].val) % MOD; } int query(int rt, int l, int r){ if(l == t[rt].l && r == t[rt].r) return t[rt].val; int mid = (t[rt].l + t[rt].r) >> 1; if(l >= mid + 1){ return query(rson, l, r) % MOD; }else if(r <= mid){ return query(lson, l, r) % MOD; }else{ return (query(lson, l, mid) * query(rson, mid + 1, r)) % MOD; } } int main() { int n; while(~scanf("%d", &n)){ memset(t, 0, sizeof(t)); memset(str, 0, sizeof(str)); scanf(" %s", str); len = strlen(str); cur = 0; ans = 0; build(1, 1, len); for(int i = 0; i < n; ++i){ int a, b, c, d; scanf("%d%d", &c, &d); a = c < d ? c : d; b = c > d ? c : d; if(a >= 1 && a <= len && b >= 1 && b <= len) ans = query(1, a, b); printf("%d\n", ans); } } return 0; }