#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")
using namespace std;
template <typename T>
void uin(T &a, T b) {
  if (b < a) {
    a = b;
  }
}
template <typename T>
void uax(T &a, T b) {
  if (b > a) {
    a = b;
  }
}
const int maxn = 100 * 1000 + 228, MOD = 1e9 + 7;
string s;
int n;
vector<int> ch;
int cnt[256], W = 0;
int answer[100][100], dp[maxn], Dp[maxn], code[maxn], f[maxn];
void add(int &a, int b) {
  a += b;
  if (a >= MOD) a -= MOD;
}
long long sss = 0;
int mult(int a, int b) {
  sss = (long long)a * (long long)b;
  sss %= MOD;
  return sss;
}
int power(int a, int b) {
  int res = 1;
  while (b) {
    if (b & 1) {
      res = mult(res, a);
    }
    a = mult(a, a);
    b >>= 1;
  }
  return res;
}
void prepare() {
  f[0] = 1;
  for (int i = 1; i <= n; ++i) {
    f[i] = mult(f[i - 1], i);
  }
  dp[0] = 1;
  for (int obj : ch) {
    int x = cnt[obj];
    for (int i = n - x + 1; i >= 0; --i) {
      add(dp[i + x], dp[i]);
    }
  }
  W = mult(f[n / 2], f[n / 2]);
  for (int obj : ch) {
    W = mult(W, power(f[cnt[obj]], MOD - 2));
  }
  for (int c1i = 0; c1i < (int)ch.size(); ++c1i) {
    for (int c2i = c1i + 1; c2i < (int)ch.size(); ++c2i) {
      int c1 = ch[c1i];
      int c2 = ch[c2i];
      for (int i = 0; i <= n; ++i) {
        Dp[i] = dp[i];
      }
      int x = cnt[c1];
      for (int i = x; i <= n; ++i) {
        Dp[i] -= Dp[i - x];
        if (Dp[i] < 0) Dp[i] += MOD;
      }
      x = cnt[c2];
      for (int i = x; i <= n; ++i) {
        Dp[i] -= Dp[i - x];
        if (Dp[i] < 0) Dp[i] += MOD;
      }
      answer[c1i][c2i] = mult(2, mult(W, Dp[n / 2]));
    }
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> s;
  n = (int)s.size();
  int ptr = 0;
  for (int i = 0; i < n; ++i) {
    code[(int)s[i]] = -1;
  }
  for (int i = 0; i < n; ++i) {
    if (code[(int)s[i]] == -1) {
      code[(int)s[i]] = ptr++;
      ch.push_back((int)s[i]);
    }
    ++cnt[(int)s[i]];
  }
  prepare();
  int q;
  cin >> q;
  for (int it = 0; it < q; ++it) {
    int x, y;
    cin >> x >> y;
    int c1 = code[(int)s[x - 1]];
    int c2 = code[(int)s[y - 1]];
    if (c1 > c2) swap(c1, c2);
    if (c1 == c2) {
      cout << mult(W, dp[n / 2]) << '\n';
    } else {
      cout << answer[c1][c2] << '\n';
    }
  }
  return 0;
}
