#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long LL; typedef pair PII; typedef vector VI; typedef vector VPII; typedef pair PLL; typedef pair PIL; typedef pair PLI; typedef double DB; #define pb push_back #define mset(a, b) memset(a, b, sizeof a) #define all(x) (x).begin(), (x).end() #define bit(x) (1 << (x)) #define bitl(x) (1LL << (x)) #define sqr(x) ((x) * (x)) #define sz(x) ((int)(x.size())) #define cnti(x) (__builtin_popcount(x)) #define cntl(x) (__builtin_popcountll(x)) #define clzi(x) (__builtin_clz(x)) #define clzl(x) (__builtin_clzll(x)) #define ctzi(x) (__builtin_ctz(x)) #define ctzl(x) (__builtin_ctzll(x)) #define X first #define Y second #define Error(x) cout << #x << " = " << x << endl template inline void chkmax(T& x, U y) { if (x < y) x = y; } template inline void chkmin(T& x, U y) { if (y < x) x = y; } const int MOD = 9973; const int MN = 100005; int n; int h[MN]; char s[MN]; int modExp(int a, int b, int m) { int ret = 1; for (; b; b /= 2, a = (LL)a * a % m) { if (b & 1) ret = (LL)ret * a % m; } return ret; } int main() { int tn; while (scanf("%d%s", &n, s) == 2) { h[0] = 1; int L = strlen(s); for (int i = 1; i <= L; i++) { h[i] = (h[i - 1] * (s[i - 1] - 28)) % MOD; } while (n--) { int a, b; scanf("%d%d", &a, &b); if (a > b) swap(a, b); printf("%d\n", (h[b] * modExp(h[a - 1], MOD - 2, MOD)) % MOD); } } return 0; }