#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 20, K = 19;
const int mod = 1e9 + 7;
long long freq[N], pd[N], inv[N], ans[52][52], dp[N][2];
long long qpower(long long x, int n) {
  if (n == 0) return 1;
  long long sum = qpower(x, n / 2);
  sum = (sum * sum) % mod;
  if (n % 2 == 1) sum = (sum * x) % mod;
  return sum;
}
int to(char x) {
  if (islower(x))
    return x - 'a';
  else
    return x - 'A' + 26;
}
int main() {
  pd[0] = 1;
  for (int i = 1; i < N; i++) pd[i] = (i * pd[i - 1]) % mod;
  for (int i = 0; i < N; i++) inv[i] = qpower(pd[i], mod - 2);
  string a;
  int n;
  cin >> a;
  n = a.size();
  for (int i = 0; i < n; i++) freq[to(a[i])]++;
  dp[0][0] = 1;
  for (int i = 0; i < 52; i++)
    if (freq[i])
      for (int j = n / 2; j >= freq[i]; j--)
        dp[j][0] = (dp[j][0] + dp[j - freq[i]][0]) % mod;
  long long sig = (pd[n / 2] * pd[n / 2]) % mod;
  for (int i = 0; i < 52; i++) sig = (sig * inv[freq[i]]) % mod;
  for (int i = 0; i < 52; i++)
    for (int j = i; j < 52; j++) {
      if (!freq[i] || !freq[j]) continue;
      if (i != j && freq[i] + freq[j] > n / 2) continue;
      if (i == j) {
        if (freq[i] <= n / 2) ans[i][i] = (sig * dp[n / 2][0]) % mod;
        continue;
      }
      for (int k = 0; k <= n / 2; k++) dp[k][1] = dp[k][0];
      for (int k = freq[i]; k <= n / 2; k++)
        dp[k][1] = (dp[k][1] - dp[k - freq[i]][1] + mod) % mod;
      for (int k = freq[j]; k <= n / 2; k++)
        dp[k][1] = (dp[k][1] - dp[k - freq[j]][1] + mod) % mod;
      ans[i][j] = ans[j][i] = (2 * sig * dp[n / 2][1]) % mod;
    }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    int l = to(a[x - 1]);
    int r = to(a[y - 1]);
    printf("%d\n", ans[l][r]);
  }
  return 0;
}
