#include <bits/stdc++.h>
using namespace std;
long long read() {
  int f = 1;
  long long res = 0;
  char ch;
  do {
    ch = getchar();
    if (ch == '-') f = -f;
  } while (ch < '0' || ch > '9');
  do {
    res = res * 10 + ch - '0';
    ch = getchar();
  } while (ch >= '0' && ch <= '9');
  return f == 1 ? res : -res;
}
void fast_io() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
const int N = 100010;
const int mod = 1000000007;
const long long INF = 1e18;
int n, m, q;
int A[N], B[N];
char str[N];
int head[N * 2], to[N * 2], nxt[N * 2], tot;
void addEdge(int u, int v) {
  tot++;
  nxt[tot] = head[u];
  to[tot] = v;
  head[u] = tot;
}
template <class T>
T mmax(T a, T b) {
  return a < b ? b : a;
}
template <class T>
T mmin(T a, T b) {
  return a < b ? a : b;
}
int countOne(int set) {
  int res = 0;
  while (set) {
    res++;
    set &= set - 1;
  }
  return res;
}
bool contain(int set, int i) { return (set & (1 << i)) > 0; }
long long myPow(long long a, int p) {
  if (p == 0) return 1;
  long long res = myPow(a, p / 2);
  res *= res;
  res %= mod;
  if (p % 2 == 1) {
    res *= a;
    res %= mod;
  }
  return res;
}
void addMode(int &a, long long b) { a = (a + b) % mod; }
long long mul(long long a, long long b) { return a * b % mod; }
template <class T>
void mySwap(T &a, T &b) {
  T tmp = a;
  a = b;
  b = tmp;
}
int gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long dp[N], ndp[N];
bool has[N];
long long p[N], inv[N];
long long dp2[52][52];
long long C(int a, int b) {
  if (a == 0) return 1;
  return p[a] * inv[b] % mod * inv[a - b] % mod;
}
int getIdx(char ch) {
  if (ch >= 'a' && ch <= 'z')
    return ch - 'a';
  else
    return ch - 'A' + 26;
}
void sub(long long &a, long long b) {
  a -= b;
  if (a < 0) a += mod;
}
int main() {
  fast_io();
  cin >> str;
  n = strlen(str);
  p[0] = p[1] = 1;
  for (int i = 2; i <= n; i++) {
    p[i] = p[i - 1] * i % mod;
  }
  for (int i = 0; i <= n; i++) {
    inv[i] = myPow(p[i], mod - 2);
  }
  int cnt[52];
  memset(cnt, 0, sizeof(cnt));
  for (int i = 0; i < n; i++) {
    if (str[i] >= 'a' && str[i] <= 'z')
      cnt[str[i] - 'a']++;
    else
      cnt[str[i] - 'A' + 26]++;
  }
  vector<int> len;
  for (int i = 0; i < 52; i++)
    if (cnt[i]) len.push_back(cnt[i]);
  memset(dp, 0, sizeof(dp));
  memset(has, false, sizeof(has));
  dp[0] = 1;
  has[0] = true;
  for (int i = 0; i < len.size(); i++) {
    for (int j = n; j >= 0; j--)
      if (has[j]) {
        has[j + len[i]] = true;
        dp[j + len[i]] = (dp[j + len[i]] + dp[j]) % mod;
      }
  }
  long long total = p[n / 2] * p[n / 2] % mod;
  for (int i = 0; i < len.size(); i++) {
    total = total * inv[len[i]] % mod;
  }
  total = total * dp[n / 2] % mod;
  memset(dp2, 0, sizeof(dp2));
  for (int i = 0; i < 52; i++)
    for (int j = i + 1; j < 52; j++)
      if (cnt[i] && cnt[j] && cnt[i] + cnt[j] <= n / 2) {
        for (int k = 0; k <= n; k++) ndp[k] = dp[k];
        for (int k = cnt[i]; k <= n; k++) {
          sub(ndp[k], ndp[k - cnt[i]]);
        }
        for (int k = cnt[j]; k <= n; k++) {
          sub(ndp[k], ndp[k - cnt[j]]);
        }
        long long tmp = p[n / 2] * p[n / 2] % mod;
        for (int k = 0; k < 52; k++)
          if (cnt[k]) {
            tmp = tmp * inv[cnt[k]] % mod;
          }
        tmp = tmp * ndp[n / 2] * 2 % mod;
        dp2[i][j] = dp2[j][i] = tmp;
      }
  cin >> m;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    if (str[a] == str[b]) {
      cout << total << '\n';
    } else {
      int ia = getIdx(str[a]);
      int ib = getIdx(str[b]);
      cout << dp2[ia][ib] << '\n';
    }
  }
  return 0;
}
