#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
long long mul[1000010], inv[1000010];
int num[100];
long long A(int n, int m) {
  if (m > n) return 0;
  if (m == 0) return 1;
  long long t1 = mul[n];
  long long t2 = inv[n - m];
  return ((t1 % mod) * (t2 % mod)) % mod;
}
long long C(int n, int m) {
  if (m > n) return 0;
  if (m == n) return 1;
  if (m == 0) return 1;
  long long t1 = mul[n];
  long long t2 = inv[n - m] * inv[m];
  return ((t1 % mod) * (t2 % mod)) % mod;
}
long long pw(long long a, int b) {
  long long ret = 1;
  while (b) {
    if (b & 1) ret = (ret * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return ret;
}
long long dpp[200000], dp[200000];
long long res[200][200];
int id(char c) {
  if (c <= 'z' && c >= 'a') return c - 'a';
  return c - 'A' + 26;
}
void init() {
  mul[0] = 1;
  inv[0] = 1;
  mul[1] = 1;
  inv[1] = 1;
  for (int i = 2; i <= 100000; ++i) {
    mul[i] = (mul[i - 1] * i) % mod;
    inv[i] = (inv[i - 1] * pw(i, mod - 2)) % mod;
  }
}
int main() {
  string s;
  cin >> s;
  init();
  memset(num, 0, sizeof(num));
  int len = s.size();
  for (int i = 0; i < len; ++i) {
    num[id(s[i])]++;
  }
  memset(dp, 0, sizeof(dp));
  dp[0] = 1;
  for (int k = 0; k < 52; ++k) {
    if (num[k] == 0) continue;
    for (int j = len / 2; j >= 0; --j) {
      dp[j + num[k]] = (dp[j] + dp[j + num[k]]) % mod;
    }
  }
  for (int i = 0; i < 52; ++i) {
    if (num[i] == 0) continue;
    for (int j = 0; j < 52; ++j) {
      if (num[j] == 0) continue;
      for (int ii = 0; ii <= len / 2; ++ii) {
        dpp[ii] = dp[ii];
      }
      for (int ii = num[i]; ii <= len / 2; ++ii) {
        dpp[ii] = (dpp[ii] - dpp[ii - num[i]] + mod) % mod;
      }
      if (i != j) {
        for (int ii = num[j]; ii <= len / 2; ++ii) {
          dpp[ii] = (dpp[ii] - dpp[ii - num[j]] + mod) % mod;
        }
        res[i][j] = dpp[len / 2 - num[i] - num[j]];
      } else {
        res[i][j] = dpp[len / 2 - num[i]];
      }
    }
  }
  long long frac = (mul[len / 2] * mul[len / 2]) % mod;
  for (int i = 0; i < 52; ++i) {
    if (num[i] == 0) continue;
    frac = (frac * inv[num[i]]) % mod;
  }
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    --x;
    --y;
    int ii = id(s[x]);
    int jj = id(s[y]);
    long long ans = (2 * res[ii][jj] * frac) % mod;
    cout << ans << endl;
  }
}
