#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll md = 1e9 + 7;
constexpr ll n = ('z' - 'a' + 1) * 2;
int convertChar(char c) {
  if ('A' <= c && c <= 'Z') return c - 'A' + n / 2;
  return c - 'a';
}
inline ll pw(ll x, ll exp) {
  ll res = 1;
  while (exp) {
    if (exp & 1) res = (res * x) % md;
    x = (x * x) % md;
    exp >>= 1;
  }
  return res;
}
inline void add(ll &x, ll y) {
  x += y;
  if (x >= md) x -= md;
}
inline void sub(ll &x, ll y) {
  x -= y;
  if (x < 0) x += md;
}
inline void sbdp(vector<ll> &dp, int shift) {
  for (int i = shift; i < dp.size(); ++i) sub(dp[i], dp[i - shift]);
}
inline void addp(vector<ll> &dp, int shift) {
  for (int i = dp.size() - 1; shift <= i; --i) add(dp[i], dp[i - shift]);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  array<ll, n> chars;
  for (auto &x : chars) x = 0;
  string s;
  cin >> s;
  for (int i = 0; i < s.size(); ++i) ++chars[convertChar(s[i])];
  vector<ll> factorials(s.size() + 1);
  factorials[0] = 1;
  for (int i = 1; i <= s.size(); ++i)
    factorials[i] = (factorials[i - 1] * i) % md;
  ll mp = factorials[s.size() / 2];
  mp = (mp * mp) % md;
  for (int i = 0; i < n; ++i) {
    if (chars[i] == 0) continue;
    mp = (mp * pw(factorials[chars[i]], md - 2)) % md;
  }
  array<array<ll, n>, n> ans;
  vector<ll> dp(s.size() + 1, 0);
  dp[0] = 1;
  for (int i = 0; i < n; ++i) {
    if (chars[i] == 0) continue;
    addp(dp, chars[i]);
  }
  for (auto &x : ans)
    for (auto &y : x) y = 0;
  for (int i = 0; i < n; ++i) {
    if (chars[i] == 0) continue;
    ans[i][i] = dp[s.size() / 2];
    sbdp(dp, chars[i]);
    for (int j = i + 1; j < n; ++j) {
      if (chars[j] == 0) continue;
      sbdp(dp, chars[j]);
      ans[j][i] = ans[i][j] = (2 * dp[s.size() / 2]) % md;
      addp(dp, chars[j]);
    }
    addp(dp, chars[i]);
  }
  int q, a, b;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    cin >> a >> b;
    a = convertChar(s[a - 1]);
    b = convertChar(s[b - 1]);
    cout << (mp * ans[a][b]) % md << '\n';
  }
  return 0;
}
