#include #include const int N = 100002; const int mod = 9973; int n, ls; int a[N]; char s[N]; inline int pow(int a, int n) { int ans = 1; while (n) { if (n & 1) ans = (ans * a) % mod; a = (a * a) % mod; n >>= 1; } return ans; } int main() { while (scanf("%d", &n) != EOF) { scanf("%s", s + 1); ls = strlen(s + 1); a[0] = 1; for (int i = 1; i <= ls; i++) a[i] = a[i - 1] * (s[i] - 28) % mod; while (n--) { int x, y; scanf("%d%d", &x, &y); printf("%d\n", a[y] * pow(a[x - 1], mod - 2) % mod); } } return 0; }