#include #include #include #include #include #include #include #include #include #include #include #include #include #define fur(i,a,b) for(int i=(a);i<=(b);i++) using namespace std; inline int extend_gcd(int a, int b, int &x, int &y) { if (a == 0 && b == 0) return -1; if (b == 0) { x = 1; y = 0; return a; } long long d = extend_gcd(b, a % b, y, x); y -= a / b * x; return d; } inline int mod_reverse(int a, int n) { int x, y, d = extend_gcd(a, n, x, y); if (d == 1) return (x % n + n) % n; else return -1; } int NY[9999]; int pre[100005]; int main() { fur(i,0,9973) NY[i] = mod_reverse(i, 9973); int n; while (~scanf("%d", &n)) { getchar(); char s[100005]; gets(s); int len = strlen(s); pre[0] = 1; int tmp = 1; fur(i,0,len-1) { tmp = (tmp * (s[i] - 28)) % 9973; pre[i + 1] = tmp; } int a, b; fur(i,1,n) { scanf("%d %d", &a, &b); if (a > b) { puts("0"); continue; } else if (a == 1) { int ans = pre[b]; printf("%d\n", ans); continue; } int ans = pre[b]; int ny = NY[pre[a - 1]]; ans = (ans * ny) % 9973; printf("%d\n", ans); } } return 0; }