#include <bits/stdc++.h>
clock_t t = clock();
namespace my_std {
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T>
inline T rnd(T l, T r) {
  return uniform_int_distribution<T>(l, r)(rng);
}
template <typename T>
inline bool chkmax(T& x, T y) {
  return x < y ? x = y, 1 : 0;
}
template <typename T>
inline bool chkmin(T& x, T y) {
  return x > y ? x = y, 1 : 0;
}
template <typename T>
inline void read(T& t) {
  t = 0;
  char f = 0, ch = getchar();
  double d = 0.1;
  while (ch > '9' || ch < '0') f |= (ch == '-'), ch = getchar();
  while (ch <= '9' && ch >= '0') t = t * 10 + ch - 48, ch = getchar();
  if (ch == '.') {
    ch = getchar();
    while (ch <= '9' && ch >= '0') t += d * (ch ^ 48), d *= 0.1, ch = getchar();
  }
  t = (f ? -t : t);
}
template <typename T, typename... Args>
inline void read(T& t, Args&... args) {
  read(t);
  read(args...);
}
char __sr[1 << 21], __z[20];
int __C = -1, __Z = 0;
inline void Ot() { fwrite(__sr, 1, __C + 1, stdout), __C = -1; }
inline void print(register int x) {
  if (__C > 1 << 20) Ot();
  if (x < 0) __sr[++__C] = '-', x = -x;
  while (__z[++__Z] = x % 10 + 48, x /= 10)
    ;
  while (__sr[++__C] = __z[__Z], --__Z)
    ;
  __sr[++__C] = '\n';
}
void file() {}
inline void chktime() {}
long long ksm(long long x, int y) {
  long long ret = 1;
  for (; y; y >>= 1, x = x * x % 1000000007)
    if (y & 1) ret = ret * x % 1000000007;
  return ret;
}
long long inv(long long x) { return ksm(x, 1000000007 - 2); }
}  // namespace my_std
using namespace my_std;
int n, m, K;
char s[101101];
int a[101101], aa[101101];
int cnt[233];
long long T;
long long fac[101101], _fac[101101];
void init() {
  fac[0] = _fac[0] = 1;
  for (int i = (1); i <= (101101 - 1); i++)
    fac[i] = fac[i - 1] * i % 1000000007, _fac[i] = inv(fac[i]);
}
long long C(int n, int m) {
  return n >= m && m >= 0
             ? fac[n] * _fac[m] % 1000000007 * _fac[n - m] % 1000000007
             : 0;
}
int sum[66];
long long dp[101101], cur[101101];
long long ans[66][66];
void Init() {
  for (int i = (1); i <= (K); i++) sum[i] = sum[i - 1] + cnt[i];
  dp[0] = 1;
  int n = ::n >> 1;
  for (int i = (1); i <= (K); i++)
    for (int j = (n); j >= (cnt[i]); j--)
      dp[j] = (dp[j] + dp[j - cnt[i]]) % 1000000007;
}
long long solve(int x, int y) {
  int n = ::n >> 1;
  if ((cnt[x] > n && x == y) || (cnt[x] + cnt[y] > n && x != y)) return 0;
  long long c = fac[n] * fac[n] % 1000000007 * inv(T) % 1000000007;
  if (x == y) return c * dp[n] % 1000000007;
  for (int i = (0); i <= (n); i++) cur[i] = dp[i];
  for (int j = (cnt[x]); j <= (n); j++)
    cur[j] = (cur[j] - cur[j - cnt[x]] + 1000000007) % 1000000007;
  for (int j = (cnt[y]); j <= (n); j++)
    cur[j] = (cur[j] - cur[j - cnt[y]] + 1000000007) % 1000000007;
  return c * cur[n - cnt[x] - cnt[y]] * 2 % 1000000007;
}
int main() {
  file();
  cin >> (s + 1);
  n = strlen(s + 1);
  for (int i = (1); i <= (n); i++) a[i] = aa[i] = s[i];
  sort(aa + 1, aa + n + 1);
  K = unique(aa + 1, aa + n + 1) - aa - 1;
  for (int i = (1); i <= (n); i++)
    a[i] = lower_bound(aa + 1, aa + K + 1, a[i]) - aa;
  for (int i = (1); i <= (n); i++) ++cnt[a[i]];
  init();
  Init();
  T = 1;
  for (int i = (1); i <= (K); i++) T = T * fac[cnt[i]] % 1000000007;
  for (int i = (1); i <= (K); i++)
    for (int j = (1); j <= (K); j++) ans[i][j] = solve(i, j);
  read(m);
  int x, y;
  while (m--) read(x, y), printf("%lld\n", ans[a[x]][a[y]]);
  return 0;
}
