#include <bits/stdc++.h>
using namespace std;
using namespace chrono;
const int N = 100005;
const int M = 1e9 + 7;
long long qpow(long long a, long long n, long long p) {
  long long r = 1;
  for (a %= p; n; n >>= 1, (a *= a) %= p)
    if (n & 1) (r *= a) %= p;
  return r;
}
int sz[52];
char s[N];
int get_chr(char c) {
  if (c >= 'A' && c <= 'Z')
    return c - 'A';
  else if (c >= 'a' && c <= 'z')
    return c - 'a' + 26;
}
long long fac[N], ans[52][52], dp0[N], dp1[N], dp2[N];
int main() {
  time_point<steady_clock> start = steady_clock::now();
  fac[0] = 1;
  for (int i = 1; i < N; i++) fac[i] = fac[i - 1] * i % M;
  int n, q, x, y;
  scanf("%s%d", s, &q);
  n = strlen(s);
  for (int i = 0; i < n; i++) sz[get_chr(s[i])]++;
  long long X = fac[n / 2] * fac[n / 2] % M;
  for (int i = 0; i < 52; i++) (X *= qpow(fac[sz[i]], M - 2, M)) %= M;
  dp0[0] = 1;
  for (int i = 0; i < 52; i++)
    for (int j = n / 2; sz[i] && j >= sz[i]; j--)
      (dp0[j] += dp0[j - sz[i]]) %= M;
  long long Y = dp0[n / 2] * X % M;
  for (int c1 = 0; c1 < 52; c1++) {
    if (!sz[c1]) continue;
    ans[c1][c1] = Y;
    memcpy((dp1), (dp0), sizeof(dp0));
    for (int j = sz[c1]; j <= n / 2; j++)
      ((dp1[j] -= dp1[j - sz[c1]]) += M) %= M;
    for (int c2 = c1 + 1; c2 < 52; c2++) {
      if (!sz[c2]) continue;
      memcpy((dp2), (dp1), sizeof(dp1));
      for (int j = sz[c2]; j <= n / 2; j++)
        ((dp2[j] -= dp2[j - sz[c2]]) += M) %= M;
      ans[c1][c2] = ans[c2][c1] =
          (dp0[n / 2] -
           ((dp0[n / 2] - dp1[n / 2] + M) % M - dp2[n / 2] + M) * 2 % M + M) *
          X % M;
    }
  }
  while (q--) {
    scanf("%d%d", &x, &y);
    printf("%lld\n", ans[get_chr(s[x - 1])][get_chr(s[y - 1])]);
  }
  cerr << endl
       << "------------------------------" << endl
       << "Time: "
       << duration<double, milli>(steady_clock::now() - start).count() << " ms."
       << endl;
  return 0;
}
