#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7, MAX_N = 1e5 + 47, MAX_T = 52;
long long get_id(char v) {
  return (v >= 'a' && v <= 'z' ? v - 'a' : v - 'A' + 26);
}
long long mul(long long a, long long b) { return (a * b) % MOD; }
long long add(long long a, long long b) {
  a += b;
  if (a >= MOD) {
    a -= MOD;
  }
  if (a < 0) {
    a += MOD;
  }
  return a;
}
long long binpow(long long a, long long p) {
  long long res = 1;
  while (p) {
    if (p & 1) {
      res = mul(res, a);
    }
    p >>= 1;
    a = mul(a, a);
  }
  return res;
}
long long f[MAX_N], dp[MAX_N], n, K, cost[MAX_T], ans[MAX_T][MAX_T];
signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  string s;
  cin >> s;
  for (auto x : s) {
    cost[get_id(x)]++;
  }
  f[0] = 1;
  n = s.size();
  for (long long i = 1; i <= n; i++) {
    f[i] = mul(f[i - 1], i);
  }
  K = mul(mul(f[n / 2], f[n / 2]), 2);
  for (long long i = 0; i < MAX_T; i++) {
    if (cost[i]) {
      K = mul(K, binpow(f[cost[i]], MOD - 2));
    }
  }
  for (long long i = 0; i < MAX_T; i++) {
    if (cost[i]) {
      fill(dp, dp + MAX_N, 0);
      dp[cost[i]] = 1;
      for (long long id = 0; id < MAX_T; id++) {
        if (cost[id] && id != i) {
          for (long long len = n / 2 - cost[id]; len >= 1; len--) {
            dp[len + cost[id]] = add(dp[len + cost[id]], dp[len]);
          }
        }
      }
      ans[i][i] = mul(K, dp[n / 2]);
      for (long long id = i + 1; id < MAX_T; id++) {
        if (cost[id] == 0) {
          continue;
        }
        for (long long len = 1; len <= n / 2 - cost[id]; len++) {
          dp[len + cost[id]] = add(dp[len + cost[id]], -dp[len]);
        }
        ans[id][i] = ans[i][id] = mul(K, dp[n / 2 - cost[id]]);
        for (long long len = n / 2 - cost[id]; len >= 1; len--) {
          dp[len + cost[id]] = add(dp[len + cost[id]], dp[len]);
        }
      }
    }
  }
  long long q;
  cin >> q;
  while (q--) {
    long long i, j;
    cin >> i >> j;
    i--;
    j--;
    i = get_id(s[i]);
    j = get_id(s[j]);
    cout << ans[i][j] << '\n';
  }
  return 0;
}
