#include #include using namespace std; int n; char str[100010]; int mul[100010]; int myDiv(int a, int b) { int c = 1, d = b; for (int i = 0; (1 << i) <= 9971; i++) { if ((1 << i) & 9971) { c = c * d % 9973; } d = d * d % 9973; } int ans = a * c % 9973; return ans; } int main() { while (scanf("%d", &n) == 1) { scanf("%s", str); mul[0] = 1; int m = strlen(str); for (int i = 1; i <= m; i++) { mul[i] = mul[i - 1] * (str[i - 1] - 28) % 9973; } for (int i = 1; i <= n; i++) { int l, r; scanf("%d%d", &l, &r); int ans = myDiv(mul[r], mul[l - 1]); printf("%d\n", ans); } } return 0; }