#include <bits/stdc++.h>
const int N = 1e5 + 5;
const long long mod = 1e9 + 7;
long long f[N], dp[N], w[55][55];
int n, q, num[55];
char s[N];
long long qpow(long long x, long long y) {
  long long res = 1;
  for (; y; y >>= 1, x = x * x % mod)
    if (y & 1) res = res * x % mod;
  return res;
}
int id(char x) {
  if (x >= 'A' && x <= 'Z') return x - 'A';
  return 26 + x - 'a';
}
int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1) >> 1;
  for (int i = 1; i <= n + n; i++) num[id(s[i])]++;
  f[0] = 1;
  for (int i = 1; i <= n + n; i++) f[i] = f[i - 1] * i % mod;
  long long ans = f[n] * f[n] * 2 % mod;
  for (int i = 0; i < 52; i++) ans = ans * qpow(f[num[i]], mod - 2) % mod;
  dp[0] = 1;
  for (int i = 0; i < 52; i++)
    if (num[i])
      for (int j = n; j >= num[i]; j--) dp[j] = (dp[j] + dp[j - num[i]]) % mod;
  for (int i = 0; i < 52; i++) {
    if (!num[i]) continue;
    for (int j = num[i]; j <= n; j++)
      dp[j] = (dp[j] - dp[j - num[i]] + mod) % mod;
    w[i][i] = ans * dp[n] % mod;
    for (int j = i + 1; j < 52; j++) {
      if (!num[j]) continue;
      for (int k = num[j]; k <= n; k++)
        dp[k] = (dp[k] - dp[k - num[j]] + mod) % mod;
      w[i][j] = w[j][i] = ans * dp[n] % mod;
      for (int k = n; k >= num[j]; k--) dp[k] = (dp[k] + dp[k - num[j]]) % mod;
    }
    for (int j = n; j >= num[i]; j--) dp[j] = (dp[j] + dp[j - num[i]]) % mod;
  }
  scanf("%d", &q);
  int x, y;
  while (q--) {
    scanf("%d%d", &x, &y);
    printf("%lld\n", w[id(s[x])][id(s[y])]);
  }
  return 0;
}
