#include <bits/stdc++.h>
using namespace std;
int n, m, q, tot, cnt[52], dp[50005], ans[52][52], eq;
long long fac[50005], mul;
char x[100005];
bool gg;
int ta, tb;
long long po(long long b, int p) {
  long long re = 1;
  while (p) {
    if (p & 1) re = re * b % 1000000007;
    b = b * b % 1000000007;
    p >>= 1;
  }
  return re;
}
void add(int &a, int b) {
  a += b;
  if (a >= 1000000007) a -= 1000000007;
}
void sub(int &a, int b) {
  a += 1000000007 - b;
  if (a >= 1000000007) a -= 1000000007;
}
void push(int a, int b) {
  for (int i = min(b, tot); i >= 0; i--) add(dp[i + a], dp[i]);
  tot += a;
}
void push(int a) { push(a, m - a); }
void pop(int a, int b) {
  tot -= a;
  ta = min(b, tot);
  for (int i = 0; i <= ta; i++) sub(dp[i + a], dp[i]);
}
void pop(int a) { pop(a, m - a); }
int main() {
  scanf("%s", x);
  n = strlen(x);
  fac[0] = 1;
  m = n / 2;
  for (int i = 1; i <= m; i++) fac[i] = fac[i - 1] * i % 1000000007;
  mul = fac[m] * fac[m] % 1000000007;
  for (int i = 0; i < n; i++) {
    if (x[i] >= 'a')
      x[i] = x[i] - 'a' + 26;
    else
      x[i] -= 'A';
    cnt[x[i]]++;
  }
  dp[0] = 1;
  for (int i = 0; i < 52; i++)
    if (cnt[i]) {
      if (cnt[i] > m) {
        gg = 1;
        break;
      }
      push(cnt[i]);
      mul = mul * po(fac[cnt[i]], 1000000007 - 2) % 1000000007;
    }
  if (!gg) {
    for (int i = 0; i < 52; i++)
      if (cnt[i] && cnt[i] < m) {
        pop(cnt[i]);
        for (int j = i + 1; j < 52; j++)
          if (cnt[j] && cnt[i] + cnt[j] <= m) {
            pop(cnt[j], m - cnt[i] - cnt[j] - cnt[j]);
            ans[i][j] = dp[m - cnt[i] - cnt[j]] * 2 * mul % 1000000007;
            push(cnt[j], m - cnt[i] - cnt[j] - cnt[j]);
          }
        push(cnt[i]);
      }
    eq = dp[m] * mul % 1000000007;
  }
  scanf("%d", &q);
  while (q--) {
    scanf("%d%d", &ta, &tb);
    ta = x[ta - 1];
    tb = x[tb - 1];
    if (ta == tb)
      printf("%d\n", eq);
    else {
      if (ta > tb) swap(ta, tb);
      printf("%d\n", ans[ta][tb]);
    }
  }
  return 0;
}
