#include <bits/stdc++.h>
using namespace std;
const int Mod = 1e9 + 7;
int f[50005], n, ans[55][55], mp[150], cnt[55], fac[100005], inv[100005],
    g[50005];
char s[100005];
int power(int b, int e) {
  if (!e) return 1;
  int tmp = power(b, e >> 1);
  tmp = 1ll * tmp * tmp % Mod;
  if (e & 1) tmp = 1ll * tmp * b % Mod;
  return tmp;
}
int main() {
  fac[0] = inv[0] = 1;
  for (int i = 1; i <= 1e5; i++)
    fac[i] = 1ll * i * fac[i - 1] % Mod, inv[i] = power(fac[i], Mod - 2);
  for (int i = 'A'; i <= 'Z'; i++) mp[i] = i - 'A' + 1;
  for (int i = 'a'; i <= 'z'; i++) mp[i] = i - 'a' + 27;
  scanf("%s", s + 1);
  n = strlen(s + 1);
  for (int i = 1; i <= n; i++) cnt[mp[s[i]]]++;
  f[0] = 1;
  for (int i = 1; i <= 52; i++)
    if (cnt[i])
      for (int j = n / 2; j >= cnt[i]; j--) f[j] = (f[j] + f[j - cnt[i]]) % Mod;
  int W = 1ll * fac[n / 2] * fac[n / 2] % Mod;
  for (int i = 1; i <= 52; i++) W = 1ll * W * inv[cnt[i]] % Mod;
  for (int i = 1; i <= 52; i++) ans[i][i] = 1ll * W * f[n / 2] % Mod;
  for (int i = 1; i <= 52; i++)
    for (int j = i + 1; j <= 52; j++) {
      memcpy(g, f, sizeof g);
      for (int k = cnt[i]; k <= n / 2; k++)
        g[k] = (g[k] - g[k - cnt[i]] + Mod) % Mod;
      for (int k = cnt[j]; k <= n / 2; k++)
        g[k] = (g[k] - g[k - cnt[j]] + Mod) % Mod;
      ans[i][j] = ans[j][i] = 2ll * W * g[n / 2] % Mod;
    }
  int q;
  cin >> q;
  while (q--) {
    int x, y;
    cin >> x >> y;
    cout << ans[mp[s[x]]][mp[s[y]]] << '\n';
  }
  return 0;
}
