#include #include #include #include #include #include #include #include #include #include #include #define MAXN 500010 using namespace std; struct node { int l,r,key; }tree[MAXN*4]; int n,m; char s[MAXN]; int f[MAXN]; const int mod=9973; void build(int num,int l,int r) { tree[num].l=l; tree[num].r=r; if (l==r) tree[num].key=(s[l]-28) % mod; else { int mid=(l+r)/2; build(num*2,l,mid); build(num*2+1,mid+1,r); tree[num].key=tree[num*2].key*tree[num*2+1].key%mod; } } int query(int num,int l,int r) { if (tree[num].l==l && tree[num].r==r) return tree[num].key; else { int mid=(tree[num].l+tree[num].r)/2; if (l>mid) return query(num*2+1,l,r) % mod; else { if (r<=mid) return query(num*2,l,r) % mod; else return query(num*2,l,mid)*query(num*2+1,mid+1,r) % mod; } } } int pow_m(int a,int b) { if (b==0) return 1; if (b==1) return a % mod; int tmp=pow_m(a,b/2) % mod; if (b % 2) return tmp*tmp % mod * a % mod; else return tmp*tmp % mod; } int main() { //freopen("input.txt","r",stdin); //freopen("output.txt","w",stdout); while (scanf("%d\n",&m)!=EOF) { gets(s+1); n=strlen(s+1); f[0]=1; for (int i=1; i<=n; i++) f[i]=(s[i]-28)*f[i-1] % mod; while (m--) { int x,y; scanf("%d%d",&x,&y); if (x>y) swap(x,y); printf("%d\n",f[y]*pow_m(f[x-1],mod-2) % mod); } /*build(1,1,n); while (m--) { int x,y; scanf("%d%d\n",&x,&y); if (x>y) swap(x,y); printf("%d\n",query(1,x,y) % mod); }*/ } return 0; }