#include <bits/stdc++.h>
using namespace std;
const int N = 100010, M = 26;
int dp[53][N], c[N], d[N], f[N];
int a[52], ans[52][52];
long long pwr(long long a, long long b) {
  long long r = 1;
  while (b) {
    if (b % 2) r = (r * a) % 1000000007;
    b /= 2;
    a = (a * a) % 1000000007;
  }
  return r;
}
int main() {
  f[0] = 1;
  for (int i = 1; i < N; i++) f[i] = 1ll * i * f[i - 1] % 1000000007;
  string s;
  cin >> s;
  for (char c : s) {
    if (c <= 'Z')
      a[c - 'A']++;
    else
      a[M + c - 'a']++;
  }
  int n = s.size();
  for (int i = 0; i <= 52; i++) dp[i][0] = 1;
  for (int i = 1; i <= 52; i++) {
    for (int j = n; j > 0; j--) {
      dp[i][j] = dp[i - 1][j];
      if (j >= a[i - 1] && a[i - 1])
        dp[i][j] = (dp[i][j] + dp[i - 1][j - a[i - 1]]) % 1000000007;
    }
  }
  long long res = 1ll * f[n / 2] * f[n / 2] % 1000000007;
  for (int i = 0; i < 52; i++)
    res = 1ll * res * pwr(f[a[i]], 1000000007 - 2) % 1000000007;
  for (int i = 0; i < 52; i++) {
    memcpy(c, dp[52], sizeof dp[52]);
    for (int j = a[i]; j <= n; j++)
      c[j] = (c[j] - c[j - a[i]] + 1000000007) % 1000000007;
    for (int j = i + 1; j < 52; j++) {
      memcpy(d, c, sizeof c);
      for (int k = a[j]; k <= n; k++)
        d[k] = (d[k] - d[k - a[j]] + 1000000007) % 1000000007;
      if (a[i] + a[j] <= n / 2)
        ans[i][j] = d[n / 2 - a[i] - a[j]];
      else
        ans[i][j] = 0;
    }
  }
  int q;
  cin >> q;
  while (q--) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    if (s[x] == s[y]) {
      cout << 1ll * res * dp[52][n / 2] % 1000000007 << " \n";
      continue;
    }
    if (s[x] <= 'Z')
      x = s[x] - 'A';
    else
      x = M + s[x] - 'a';
    if (s[y] <= 'Z')
      y = s[y] - 'A';
    else
      y = M + s[y] - 'a';
    if (x > y) swap(x, y);
    assert(x < y);
    cout << 2ll * res * ans[x][y] % 1000000007 << "\n";
  }
  return 0;
}
