#include #include #include using namespace std; const int maxn = 1000005; const int mod = 9973; #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 string s; int tree[maxn<<2]; void push_up(int rt) { tree[rt]=tree[rt<<1]*tree[rt<<1|1]%mod; } void make(int l,int r,int rt) { if(l==r) { tree[rt]=s[l-1]-28; return ; } int m=(l+r)>>1; make(lson); make(rson); push_up(rt); } int query(int L,int R,int l,int r,int rt) { if(L<=l&&R>=r) { return tree[rt]; } int m=(l+r)>>1; int re=1; if(L<=m) re=re*query(L,R,lson)%mod; if(R>m) re=re*query(L,R,rson)%mod; return re; } int a,b; int main() { //freopen("input.txt","r",stdin); //freopen("output.txt","w",stdout); //cin.sync_with_stdio(false); //cout.sync_with_stdio(false); int n; while(cin>>n) { getchar(); getline(cin,s); int len=s.length(); make(1,len,1); int last; for(int i=1;i<=n;++i) { scanf("%d %d",&a,&b); if(a>b)swap(a,b); if(b<1||a<1||a>len||b>len) printf("%d\n",last); else { last=query(a,b,1,len,1); printf("%d\n",last); } } } return 0; }