#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 1e5 + 5;
const int ub = 1e6;
const double inf = 1e-4;
long long powmod(long long x, long long y) {
  long long t;
  for (t = 1; y; y >>= 1, x = x * x % mod)
    if (y & 1) t = t * x % mod;
  return t;
}
long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; }
char s[maxn];
int len, cnt[52], q, x, y;
long long dp[maxn], g[maxn], ans[52][52];
int idx(char c) {
  if (c <= 'z' && c >= 'a') return c - 'a';
  return 26 + c - 'A';
}
long long fac[maxn], inv[maxn];
void init() {
  fac[0] = 1;
  for (int(i) = (1); (i) < (maxn); (i)++) fac[i] = fac[i - 1] * i % mod;
  inv[maxn - 1] = powmod(fac[maxn - 1], mod - 2);
  for (int i = maxn - 2; i >= 0; i--) inv[i] = inv[i + 1] * (i + 1) % mod;
}
long long C(long long p, long long q) {
  return fac[p] * inv[q] % mod * inv[p - q] % mod;
}
void Back(int x) {
  for (int(k) = (0); (k) < (x); (k)++) g[k] = dp[k];
  for (int(k) = (x); (k) < (len / 2 + 1); (k)++)
    g[k] = (dp[k] - g[k - x] + mod) % mod;
}
int main() {
  init();
  scanf("%s", s);
  len = strlen(s);
  for (int(i) = (0); (i) < (len); (i)++) cnt[idx(s[i])]++;
  memset((dp), (0), sizeof(dp)), memset((g), (0), sizeof(g)), dp[0] = 1;
  for (int(i) = (0); (i) < (52); (i)++)
    if (cnt[i])
      for (int j = len / 2; j >= cnt[i]; j--) (dp[j] += dp[j - cnt[i]]) %= mod;
  memset((ans), (0), sizeof(ans));
  for (int(i) = (0); (i) < (52); (i)++)
    for (int(j) = (i); (j) < (52); (j)++) {
      Back(cnt[i]);
      if (i != j)
        for (int(k) = (cnt[j]); (k) < (len / 2 + 1); (k)++)
          g[k] = (g[k] - g[k - cnt[j]] + mod) % mod;
      ans[i][j] = g[len / 2];
    }
  long long xishu = fac[len / 2] * fac[len / 2] % mod;
  for (int(i) = (0); (i) < (52); (i)++) xishu = xishu * inv[cnt[i]] % mod;
  cin >> q;
  for (int(i) = (0); (i) < (q); (i)++) {
    cin >> x >> y;
    x = idx(s[x - 1]), y = idx(s[y - 1]);
    long long ret = max(ans[x][y], ans[y][x]);
    ret = ret * 2 % mod * xishu % mod;
    cout << ret << endl;
  }
  return 0;
}
