#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
const int M = 1e9 + 7;
const int L = 52;
long long modinv(long long in) {
  long long res = 1;
  int pw = M - 2;
  while (pw > 0) {
    if (pw & 1) res *= in, res %= M;
    in *= in, in %= M;
    pw >>= 1;
  }
  return res;
}
long long fact[N];
int n, q;
int cnt[L];
int ord(char c) {
  if (c >= 'a') return c - 'a';
  return c - 'A' + 26;
}
long long dp[N], tmp[N], tmp2[N];
long long ans[L][L];
long long fx(long long v) { return (v % M + M) % M; }
int main() {
  fact[1] = 1;
  for (int i = 2; i < N; i++) {
    fact[i] = fact[i - 1] * i % M;
  }
  ios::sync_with_stdio(0);
  cin.tie(0);
  string second;
  cin >> second >> q;
  n = second.length();
  for (char c : second) cnt[ord(c)]++;
  long long scl = fact[n / 2] * fact[n / 2] % M;
  dp[0] = 1;
  for (int i = 0; i < L; i++) {
    if (cnt[i] == 0) continue;
    scl *= modinv(fact[cnt[i]]);
    scl %= M;
    for (int j = n / 2; j - cnt[i] >= 0; j--)
      dp[j] += dp[j - cnt[i]], dp[j] %= M;
  }
  for (int x = 0; x < L; x++) {
    if (cnt[x] == 0) continue;
    ans[x][x] = dp[n / 2] * scl % M;
    memcpy(tmp, dp, sizeof tmp);
    for (int j = 0; j + cnt[x] <= n / 2; j++)
      tmp[j + cnt[x]] = fx(tmp[j + cnt[x]] - tmp[j]);
    for (int y = x + 1; y < L; y++) {
      if (cnt[y] == 0) continue;
      memcpy(tmp2, tmp, sizeof tmp2);
      for (int j = 0; j + cnt[y] <= n / 2; j++)
        tmp2[j + cnt[y]] = fx(tmp2[j + cnt[y]] - tmp2[j]);
      ans[y][x] = ans[x][y] = tmp2[n / 2] * scl % M * 2 % M;
    }
  }
  for (int i = 0; i < q; i++) {
    int x, y;
    cin >> x >> y;
    x = ord(second[x - 1]), y = ord(second[y - 1]);
    printf("%lld\n", ans[x][y]);
  }
}
