#include #include #include using namespace std; const int MAXN = 1e5 + 5; int H[MAXN]; char Hstr[MAXN]; int N, l, r; const int mods = 9973; typedef long long LL; LL mod_pow(LL x, LL n, LL mod) { LL res = 1; while(n > 0) { if(n & 1) res = res * x % mod; x = x * x % mod; n >>= 1; } return res; } int main(){ while(~scanf("%d", &N)){ scanf("%s", Hstr); int len = strlen(Hstr); H[0] = 1; for(int i = 1;i <= len;i ++){ H[i] = H[i - 1] * (Hstr[i - 1] - 28) % mods; } while(N --){ scanf("%d%d", &l, &r); if(l > r) swap(l, r); printf("%I64d\n", (LL)H[r] * mod_pow(H[l - 1], mods - 2, mods) % mods); } } return 0; }