#include <bits/stdc++.h>
using namespace std;
using LL = long long;
int n, q, fac[100005], x, y, tx, ty, cnt[53], dp[50005], ddp[50005],
    res[52][52], W;
char s[100005];
int quick_power(int x, int y) {
  int res = 1, base = x;
  while (y) {
    if (y & 1) res = (LL)res * base % 1000000007;
    base = (LL)base * base % 1000000007;
    y >>= 1;
  }
  return res;
}
int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  scanf("%d", &q);
  fac[0] = 1;
  for (int i = 1; i <= n; i++) fac[i] = (LL)fac[i - 1] * i % 1000000007;
  for (int i = 1; i <= n; i++)
    if (s[i] >= 'a')
      cnt[s[i] - 'a' + 26]++;
    else
      cnt[s[i] - 'A']++;
  dp[0] = 1;
  for (int i = 0; i < 52; i++)
    if (cnt[i])
      for (int j = n / 2; j >= cnt[i]; j--)
        dp[j] = (dp[j] + dp[j - cnt[i]]) % 1000000007;
  for (int tx = 0; tx < 52; tx++)
    for (int ty = 0; ty < 52; ty++) {
      for (int i = 0; i <= n / 2; i++) ddp[i] = dp[i];
      for (int i = cnt[tx]; i <= n / 2; i++)
        ddp[i] = (ddp[i] - ddp[i - cnt[tx]] + 1000000007) % 1000000007;
      if (tx != ty)
        for (int i = cnt[ty]; i <= n / 2; i++)
          ddp[i] = (ddp[i] - ddp[i - cnt[ty]] + 1000000007) % 1000000007;
      res[tx][ty] = ddp[n / 2];
    }
  W = (LL)fac[n / 2] * fac[n / 2] % 1000000007;
  for (int i = 0; i < 52; i++)
    W = (LL)W * quick_power(fac[cnt[i]], 1000000007 - 2) % 1000000007;
  while (q--) {
    scanf("%d%d", &x, &y);
    if (s[x] >= 'a')
      tx = s[x] - 'a' + 26;
    else
      tx = s[x] - 'A';
    if (s[y] >= 'a')
      ty = s[y] - 'a' + 26;
    else
      ty = s[y] - 'A';
    printf("%lld\n", (LL)2 * W * res[tx][ty] % 1000000007);
  }
  return 0;
}
