#include #include #include #include #include #define MAX 100010 #define MOD 9973 using namespace std; typedef long long i64; char str[MAX]; int w[MAX]; i64 ModPow(i64 a, i64 b, i64 p = MOD) { i64 ret = 1; for (a %= p; b; b >>= 1) { if (b & 1) ret = ret * a % p; a = a * a % p; } return ret; } inline i64 Inv(i64 x, i64 p = MOD) { return ModPow(x, p - 2, p); } void Init(const char* str) { w[0] = 1; for (int i = 1; *str; ++str) { w[i] = w[i - 1] * (*str - 28) % MOD; ++i; } } inline int Query(int l, int r) { return w[r] * Inv(w[l - 1]) % MOD; } int main() { int n; while (~scanf("%d", &n)) { scanf("%s", str); Init(str); int l, r; for (int i = 0; i < n; ++i) { scanf("%d%d", &l, &r); printf("%d\n", Query(l, r)); } } return 0; }