#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 100;
const int MOD = 1e9 + 7;
vector<int> vC;
string s;
int q;
int quan[N];
long long fac[N], inv[N], dp[N], tmp[N];
long long ans[200][200];
long long pw(int x, int q) {
  if (q == 0) return 1;
  long long tmp = pw(x, q >> 1);
  tmp = tmp * tmp % MOD;
  if (q & 1) tmp = tmp * x % MOD;
  return tmp;
}
long long C(int k, int n) { return fac[n] * inv[k] % MOD * inv[n - k] % MOD; }
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> s;
  for (auto c : s) quan[c]++, vC.push_back(c);
  sort(vC.begin(), vC.end());
  vC.resize(unique(vC.begin(), vC.end()) - vC.begin());
  int n = s.size();
  fac[0] = 1;
  inv[0] = pw(1, MOD - 2);
  for (int i = 1; i <= n; ++i) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = inv[i - 1] * pw(i, MOD - 2) % MOD;
  }
  int m = vC.size();
  dp[0] = 1;
  for (int i = 0; i < m; ++i)
    for (int j = n / 2; j >= 0; --j)
      dp[j + quan[vC[i]]] = (dp[j + quan[vC[i]]] + dp[j]) % MOD;
  memset(ans, -1, sizeof ans);
  cin >> q;
  for (int x, y; q; q--) {
    cin >> x >> y;
    x = s[--x];
    y = s[--y];
    if (x > y) swap(x, y);
    if (ans[x][y] != -1) {
      cout << ans[x][y] << '\n';
      continue;
    }
    if (x == y ? quan[x] > n / 2 : quan[x] + quan[y] > n / 2)
      ans[x][y] = 0;
    else {
      for (int i = 0; i <= n / 2; ++i) tmp[i] = dp[i];
      for (int i = quan[x]; i <= n / 2; ++i)
        tmp[i] = (tmp[i] - tmp[i - quan[x]] + MOD) % MOD;
      if (x != y)
        for (int i = quan[y]; i <= n / 2; ++i)
          tmp[i] = (tmp[i] - tmp[i - quan[y]] + MOD) % MOD;
      int sum = (x == y ? quan[x] : quan[x] + quan[y]);
      int remain = n / 2 - sum;
      long long constant =
          (x == y ? C(quan[x], n / 2)
                  : C(quan[x], n / 2) * C(quan[y], n / 2 - quan[x]) % MOD);
      constant = constant * fac[n / 2] % MOD * fac[remain] % MOD;
      for (auto c : vC)
        if (c != x && c != y) constant = constant * inv[quan[c]] % MOD;
      ans[x][y] = tmp[n / 2] * constant % MOD;
    }
    ans[x][y] = ans[x][y] * 2 % MOD;
    cout << ans[x][y] << '\n';
  }
}
