// Problem A.cpp #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define LL long long #define lson l, m, rt<<1 #define rson m+1, r, rt<<1|1 #define PI 3.1415926535897932626 #define EXIT exit(0); #define PAUSE system("pause"); #define DEBUG puts("Here is a BUG"); #define SYNC_CLOSE ios::sync_with_stdio(false); #define what_is(x) cout << #x << " is " << x << endl; #define CLEAR(name, init) memset(name, init, sizeof(name)); const double eps = 1e-8; const int MAXN = (int)1e5 + 5; using namespace std; char s[MAXN]; LL multi[MAXN]; void ex_gcd(LL a, LL b, LL &x, LL &y) { if (b == 0) { x = 1; y = 0; return; } ex_gcd(b, a % b, y, x); y -= x * (a/b); return; } int main(int argc, char const *argv[]) { #ifndef ONLINE_JUDGE freopen("D:\\Documents\\Disk_Synchronous\\Programs\\Acm\\input.txt", "r", stdin); #endif int n; while(cin >> n) { scanf("%s", s); multi[0] = 1; multi[1] = s[0] - 28; for(int i = 1; s[i]; i++) { multi[i+1] = multi[i] * (s[i]-28) % 9973; } int m = strlen(s); for(int i = 0; i < n; i++) { int a, b; scanf("%d%d", &a, &b); /*if (a < 1 || a > m || b < 1 || b > m) { puts("1"); continue; }*/ LL x = multi[a-1], y, d; ex_gcd(x, 9973, d, y); d = (d + 9973) % 9973; printf("%I64d\n", multi[b] * d % 9973); } } return 0; }