#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int N = 100005;
const int M = 55;
int n, q;
char s[N];
int x[M];
inline int rnk(char ch) {
  return (ch >= 'a' && ch <= 'z' ? ch - 'a' + 1 : ch - 'A' + 27);
}
long long rev[N];
int dp[N], tmp1[N], tmp2[N];
int ans[M][M];
int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  for (int i = 1; i <= n; i++) x[rnk(s[i])]++;
  rev[1] = 1;
  for (int i = 2; i <= n; i++) rev[i] = (MOD - MOD / i) * rev[MOD % i] % MOD;
  long long W = 1;
  for (int i = 1; i <= n / 2; i++) W = W * i % MOD * i % MOD;
  for (int i = 1; i < M; i++)
    for (int j = 1; j <= x[i]; j++) W = W * rev[j] % MOD;
  dp[0] = 1;
  for (int i = 1; i < M; i++)
    for (int j = n; j >= x[i]; j--)
      if (x[i] > 0) dp[j] = (dp[j] + dp[j - x[i]]) % MOD;
  for (int i = 1; i < M; i++) ans[i][i] = W * dp[n / 2] % MOD;
  for (int i = 1; i < M; i++) {
    for (int j = 0; j <= n; j++) tmp1[j] = dp[j];
    for (int j = x[i]; j <= n; j++)
      tmp1[j] = (tmp1[j] - tmp1[j - x[i]] + MOD) % MOD;
    for (int j = i + 1; j < M; j++) {
      for (int k = 0; k <= n; k++) tmp2[k] = tmp1[k];
      for (int k = x[j]; k <= n; k++)
        tmp2[k] = (tmp2[k] - tmp2[k - x[j]] + MOD) % MOD;
      ans[i][j] = ans[j][i] = 2 * W * tmp2[n / 2] % MOD;
    }
  }
  scanf("%d", &q);
  while (q--) {
    int x, y;
    scanf("%d%d", &x, &y);
    printf("%d\n", ans[rnk(s[x])][rnk(s[y])]);
  }
  return 0;
}
