#include <bits/stdc++.h>
using namespace std;
int in() {
  int x;
  scanf("%d", &x);
  return x;
}
long long lin() {
  long long x;
  scanf("%lld", &x);
  return x;
}
int c2i(char c) {
  if (c >= 'a' && c <= 'z') return c - 'a';
  return c - 'A' + 26;
}
const long long mod = 1e9 + 7;
const int N = 100010;
long long fact[N], invf[N];
long long add(long long x, long long y) { return (x + y) % mod; }
long long mul(long long x, long long y) { return (x % mod) * (y % mod) % mod; }
long long powll(long long x, long long y) {
  long long res = 1LL;
  while (y) {
    if (y & 1LL) res *= x;
    res %= mod;
    x = (x * x) % mod;
    y >>= 1LL;
  }
  return res;
}
long long divll(long long x, long long y) {
  return (x * powll(y, mod - 2)) % mod;
}
long long nPr(long long n, long long r) {
  if (n < r || r < 0) return 0;
  return mul(fact[n], invf[n - r]);
}
long long nCr(long long n, long long r) {
  if (n < r || r < 0) return 0;
  return mul(mul(fact[n], invf[r]), invf[n - r]);
}
int main() {
  string s;
  cin >> s;
  fact[0] = invf[0] = 1;
  for (int i = 1; i <= N - 1; ++i) {
    fact[i] = (fact[i - 1] * i) % mod;
  }
  invf[N - 1] = divll(1, fact[N - 1]);
  for (int i = N - 1; i >= 1; --i) {
    invf[i - 1] = (invf[i] * i) % mod;
  }
  int n = s.length();
  vector<int> a(n);
  for (int i = 0; i < n; ++i) a[i] = c2i(s[i]);
  int m = 52;
  vector<int> cnt(m);
  for (int i = 0; i < n; ++i) cnt[a[i]]++;
  long long num = (fact[n / 2] * fact[n / 2]) % mod;
  for (int i = 0; i < m; ++i) num = (num * invf[cnt[i]]) % mod;
  vector<vector<int> > ans(m, vector<int>(m));
  vector<long long> dp(n + 1);
  dp[0] = 1;
  for (int i = 0; i < m; ++i) {
    if (!cnt[i]) continue;
    for (int j = n - cnt[i]; j >= 0; --j) {
      (dp[j + cnt[i]] += dp[j]) %= mod;
    }
  }
  for (int i = 0; i < m; ++i) ans[i][i] = dp[n / 2];
  for (int i = 0; i < m; ++i) {
    if (!cnt[i]) continue;
    vector<long long> dp2(dp);
    for (int j = cnt[i]; j <= n; ++j) {
      (dp2[j] += mod - dp2[j - cnt[i]]) %= mod;
    }
    for (int j = i + 1; j <= m - 1; ++j) {
      if (!cnt[j]) continue;
      for (int k = cnt[j]; k <= n; ++k) {
        (dp2[k] += mod - dp2[k - cnt[j]]) %= mod;
      }
      long long tmp = (2 * dp2[n / 2]) % mod;
      ans[i][j] = ans[j][i] = tmp;
      for (int k = n; k >= cnt[j]; --k) {
        (dp2[k] += dp2[k - cnt[j]]) %= mod;
      }
    }
  }
  int q = in();
  while (q--) {
    int l = in() - 1, r = in() - 1;
    l = a[l];
    r = a[r];
    cout << (num * ans[l][r]) % mod << endl;
  }
  return 0;
}
