#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int N = 100000 + 5;
inline int add(int a, int b) { return a + b >= MOD ? a + b - MOD : a + b; }
inline int sub(int a, int b) { return a - b < 0 ? a - b + MOD : a - b; }
inline int mul(int64_t a, int64_t b) { return static_cast<int>(a * b % MOD); }
inline int qPow(int a, int64_t k) {
  int ret = 1;
  while (k) {
    if (k & 1) ret = mul(ret, a);
    k >>= 1;
    a = mul(a, a);
  }
  return ret;
}
int jie[N], inv_jie[N];
inline int reduce(char a) {
  if (isupper(a)) return a - 'A';
  return a - 'a' + 26;
}
int cnt[52], dp[N >> 1];
int ans[52][52];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  string ss;
  cin >> ss;
  int n = static_cast<int>(ss.size()), n2 = n >> 1;
  jie[0] = 1;
  for (int i = 1; i <= n; ++i) jie[i] = mul(jie[i - 1], i);
  for (int i = 0; i <= n; ++i) inv_jie[i] = qPow(jie[i], MOD - 2);
  for (auto c : ss) cnt[reduce(c)]++;
  string tmp = ss;
  sort(tmp.begin(), tmp.end());
  tmp.resize(distance(tmp.begin(), unique(tmp.begin(), tmp.end())));
  int hao_way = mul(jie[n2], jie[n2]);
  for (auto c : tmp) hao_way = mul(hao_way, inv_jie[cnt[reduce(c)]]);
  dp[0] = 1;
  for (auto c : tmp) {
    int cc = cnt[reduce(c)];
    for (int i = n2; i >= cc; --i) dp[i] = add(dp[i], dp[i - cc]);
  }
  for (size_t i = 0; i < tmp.size(); ++i) {
    int x = reduce(tmp[i]);
    ans[x][x] = mul(dp[n2], hao_way);
    for (int c = cnt[x]; c <= n2; ++c) dp[c] = sub(dp[c], dp[c - cnt[x]]);
    for (size_t j = i + 1; j < tmp.size(); ++j) {
      int y = reduce(tmp[j]);
      for (int c = cnt[y]; c <= n2; ++c) dp[c] = sub(dp[c], dp[c - cnt[y]]);
      ans[x][y] = ans[y][x] = mul(dp[n2], hao_way);
      ans[x][y] = ans[y][x] = add(ans[x][y], ans[x][y]);
      for (int c = n2; c >= cnt[y]; --c) dp[c] = add(dp[c], dp[c - cnt[y]]);
    }
    for (int c = n2; c >= cnt[x]; --c) dp[c] = add(dp[c], dp[c - cnt[x]]);
  }
  int q;
  cin >> q;
  while (q--) {
    int i1, i2;
    cin >> i1 >> i2;
    cout << ans[reduce(ss[i1 - 1])][reduce(ss[i2 - 1])] << '\n';
  }
  return 0;
}
