#include <bits/stdc++.h>
using namespace std;
inline int Get() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while ('0' <= ch && ch <= '9') {
    x = (x << 1) + (x << 3) + ch - '0';
    ch = getchar();
  }
  return x * f;
}
const long long mod = 1e9 + 7;
char s[200005];
int n;
int num[100];
int Id(char x) { return x >= 'a' ? x - 'a' + 27 : x - 'A' + 1; }
long long fac[200005], ifac[200005];
long long ksm(long long t, long long x) {
  long long ans = 1;
  for (; x; x >>= 1, t = t * t % mod)
    if (x & 1) ans = ans * t % mod;
  return ans;
}
int f[200005], g[200005];
int Mod(int a) { return a < 0 ? a + mod : (a < mod ? a : a - mod); }
int ans[60][60];
int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  fac[0] = 1;
  for (int i = 1; i <= n; i++) fac[i] = fac[i - 1] * i % mod;
  ifac[n] = ksm(fac[n], mod - 2);
  for (int i = n - 1; i >= 0; i--) ifac[i] = ifac[i + 1] * (i + 1) % mod;
  for (int i = 1; i <= n; i++) num[Id(s[i])]++;
  f[0] = 1;
  for (int i = 1; i <= 52; i++) {
    if (!num[i]) continue;
    for (int j = n; j >= num[i]; j--) f[j] = Mod(f[j] + f[j - num[i]]);
  }
  int m = n / 2;
  long long tem = 1;
  for (int i = 1; i <= 52; i++) tem = tem * ifac[num[i]] % mod;
  tem = tem * fac[m] % mod * fac[m] % mod;
  for (int i = 1; i <= 52; i++) ans[i][i] = 1ll * f[m] * tem % mod;
  for (int i = 1; i <= 52; i++) {
    if (!num[i]) continue;
    memcpy(g, f, sizeof(f));
    for (int j = num[i]; j <= m; j++) g[j] = Mod(g[j] - g[j - num[i]]);
    for (int j = i + 1; j <= 52; j++) {
      if (!num[j]) continue;
      int t = m % num[j];
      for (int k = t + num[j]; k <= m; k += num[j])
        g[k] = Mod(g[k] - g[k - num[j]]);
      ans[i][j] = ans[j][i] = 1ll * 2 * g[m] * tem % mod;
      for (int k = m; k >= num[j]; k -= num[j])
        g[k] = Mod(g[k] + g[k - num[j]]);
    }
  }
  int Q = Get();
  while (Q--) {
    int x = Get(), y = Get();
    cout << ans[Id(s[x])][Id(s[y])] << "\n";
  }
  return 0;
}
