#include #include #include #define LL long long using namespace std; const int mod = 9973; const int N = 100010; char s[N]; int dp[N], inv[N], q; int main() { inv[0] = inv[1] = 1; for(int i = 2; i <= mod; i++) inv[i] = (mod - mod / i) * inv[mod % i] % mod; while (~scanf("%d", &q)) { scanf("%s", s + 1); int l = strlen(s + 1); dp[0] = 1; for (int i = 1; i <= l; ++i) dp[i] = (dp[i - 1] * (s[i] - 28)) % mod; while (q--) { int a, b; scanf("%d%d", &a, &b); printf("%d\n", (dp[b] * inv[dp[a - 1]]) % mod); } } return 0; }