#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const int MOD = 1e9 + 7;
string s;
int n, q, half, constValue;
int cnt[60], dp[N], fact[N], ans[60][60];
int num(char c) {
  if (c >= 'a' && c <= 'z') return c - 'a';
  return c - 'A' + 26;
}
int Power(int a, int b) {
  if (b == 1) return a;
  int t = Power(a, b / 2);
  return ((1LL * t * t % MOD) * ((b % 2 == 0) ? 1 : a)) % MOD;
}
void add(int val) {
  for (int i = n; i >= val; i--) dp[i] = (dp[i] + dp[i - val]) % MOD;
}
void del(int val) {
  for (int i = val; i <= n; i++) dp[i] = (dp[i] - dp[i - val] + MOD) % MOD;
}
int main() {
  ios ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  if (fopen("main.in", "r")) freopen("main.in", "r", stdin);
  cin >> s;
  n = s.size();
  half = n >> 1;
  for (int i = 0; i < n; i++) cnt[num(s[i])]++;
  dp[0] = 1;
  for (int c = 0; c < 52; c++)
    if (cnt[c]) add(cnt[c]);
  for (int c = 0; c < 52; c++)
    if (cnt[c]) ans[c][c] = dp[half];
  for (int first = 0; first < 52; first++) {
    if (cnt[first] == 0) continue;
    del(cnt[first]);
    for (int second = 0; second < 52; second++) {
      if (cnt[second] == 0 || second == first) continue;
      del(cnt[second]);
      ans[first][second] = (2LL * dp[half]) % MOD;
      add(cnt[second]);
    }
    add(cnt[first]);
  }
  fact[0] = 1;
  for (int i = 1; i <= n; i++) fact[i] = 1LL * fact[i - 1] * i % MOD;
  constValue = (1LL * fact[n / 2] * fact[n / 2]) % MOD;
  for (int c = 0; c < 52; c++)
    if (cnt[c])
      constValue = 1LL * constValue * Power(fact[cnt[c]], MOD - 2) % MOD;
  cin >> q;
  while (q--) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    int result = (1LL * ans[num(s[x])][num(s[y])] * constValue) % MOD;
    cout << result << '\n';
  }
  return 0;
}
