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