#include <bits/stdc++.h>
const int inf = 1e9 + 7;
using namespace std;
long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  return f * x;
}
long long ans, p[100005], inv[100005], invp[100005];
char s[100005];
int n, m, a[53], _x, _y, d[53][53];
struct tmp {
  int d[100005];
  void operator*=(const int &t) {
    for (int i = n; i >= t; i--) d[i] += d[i - t], d[i] %= inf;
  }
  void operator/=(const int &t) {
    for (int i = t; i <= n; i++) d[i] -= d[i - t], d[i] %= inf;
  }
} cnt[53];
int fun(char t) { return 'a' <= t && t <= 'z' ? t - 'a' + 1 : t - 'A' + 27; }
int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  p[0] = invp[0] = inv[1] = invp[1] = 1;
  for (int i = 1; i <= n; i++) p[i] = p[i - 1] * i % inf;
  for (int i = 2; i <= n; i++)
    inv[i] = inv[inf % i] * (inf - inf / i) % inf,
    invp[i] = invp[i - 1] * inv[i] % inf;
  for (int i = 1; i <= n; i++) a[fun(s[i])]++;
  n >>= 1;
  ans = p[n] * p[n] % inf;
  for (int i = 1; i <= 52; i++) ans *= invp[a[i]], ans %= inf;
  ans <<= 1;
  ans %= inf;
  cnt[0].d[0] = 1;
  for (int i = 1; i <= 52; i++)
    if (a[i]) cnt[0] *= a[i];
  for (int i = 1; i <= 52; i++)
    if (a[i]) cnt[i] = cnt[0], cnt[i] /= a[i];
  for (int i = 1; i <= 52; i++)
    if (a[i])
      for (int j = i + 1; j <= 52; j++)
        if (a[j]) {
          int t = 1;
          for (int k = n; k >= 0; k -= a[j], t = -t)
            d[i][j] += t * cnt[i].d[k], d[i][j] %= inf;
        }
  for (int i = 1; i <= 52; i++)
    for (int j = 1; j <= i - 1; j++) d[i][j] = d[j][i];
  m = read();
  while (m--) {
    _x = read();
    _y = read();
    if (s[_x] == s[_y])
      printf("%lld\n", (cnt[fun(s[_x])].d[n] + inf) * ans % inf);
    else
      printf("%lld\n", (d[fun(s[_x])][fun(s[_y])] + inf) * ans % inf);
  }
  return 0;
}
