#include #include using namespace std; const int MOD = 9973; int h[100010]; int mod_pow(int a, int b) { int ret = 1; while (b > 0) { if (b & 1) ret = ret * a % MOD; a = a * a % MOD; b >>= 1; } return ret; } int get_hash(int l, int r) { return h[r] * mod_pow(h[l - 1], MOD - 2) % MOD; } int main(void) { ios::sync_with_stdio(false); int n; while (cin >> n) { string s; cin >> s; h[0] = 1; int m = s.length(); for (int i = 1; i <= m; ++ i) { h[i] = h[i - 1] * (s[i - 1] - 28) % MOD; } for (int i = 0; i < n; ++ i) { int l, r; cin >> l >> r; cout << get_hash(l, r) << endl; } } return 0; }