#include <bits/stdc++.h>
using namespace std;
const long long Mod = 1e9 + 7;
const long long N = 200005;
const long long Len = 55;
long long f[N], Ans[55][55], a[N], num[55], n, m;
long long frac[N], inv[N], ans, q;
char s[N];
inline long long read() {
  long long x = 0, ff = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') ff = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 1) + (x << 3) + (ch ^ 48);
    ch = getchar();
  }
  return x * ff;
}
inline long long power(long long a, long long b) {
  long long res = 1;
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % Mod;
    a = a * a % Mod;
  }
  return res;
}
inline void prework() {
  for (long long i = 1; i <= n; i++) {
    if (s[i] >= 'a' && s[i] <= 'z')
      a[i] = s[i] - 'a' + 1;
    else
      a[i] = s[i] - 'A' + 1 + 26;
    num[a[i]]++;
  }
  frac[0] = 1;
  for (long long i = 1; i <= N - 5; i++) frac[i] = frac[i - 1] * i % Mod;
  inv[N - 5] = power(frac[N - 5], Mod - 2) % Mod;
  for (long long i = N - 6; i >= 0; i--) inv[i] = inv[i + 1] * (i + 1) % Mod;
  return;
}
inline void insert(long long x) {
  if (!num[x]) return;
  for (long long j = m; j >= num[x]; j--) f[j] = (f[j] + f[j - num[x]]) % Mod;
}
inline void Delete(long long x) {
  if (!num[x]) return;
  for (long long j = num[x]; j <= m; j++)
    f[j] = (f[j] - f[j - num[x]] + Mod) % Mod;
}
inline void solve() {
  ans = frac[m] * frac[m] % Mod;
  f[0] = 1;
  for (long long i = 1; i <= 52; i++) {
    if (!num[i]) continue;
    insert(i);
    ans = ans * inv[num[i]] % Mod;
  }
  for (long long i = 1; i <= 52; i++) {
    Delete(i);
    for (long long j = i + 1; j <= 52; j++) {
      Delete(j);
      Ans[i][j] = f[m] * 2 % Mod;
      insert(j);
    }
    insert(i);
  }
}
signed main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  m = n >> 1;
  prework();
  solve();
  q = read();
  while (q--) {
    long long x, y;
    x = read();
    y = read();
    if (a[x] == a[y])
      printf("%lld\n", ans * f[m] % Mod);
    else {
      if (a[x] > a[y]) swap(x, y);
      printf("%lld\n", Ans[a[x]][a[y]] * ans % Mod);
    }
  }
  return 0;
}
