Problem: There is a colony of villains with several holes aligned in a row, where each hole contains exactly one villain.

Each colony arrangement can be expressed as a string of even length, where the i-th character of the string represents the type of villain in the i-th hole. 

Iron Man can destroy a colony only if the colony arrangement is such that all villains of a certain type either live in the first half of the colony or in the second half of the colony.

His assistant Jarvis has a special power. It can swap villains of any two holes, i.e. swap any two characters in the string; he can do this operation any number of times.

Now Iron Man asks Jarvis q questions. In each question, he gives Jarvis two numbers x and y. Jarvis has to tell Iron Man the number of distinct colony arrangements he can create from the original one using his powers such that all villains having the same type as those originally living in x-th hole or y-th hole live in the same half and the Iron Man can destroy that colony arrangement.

Two colony arrangements are considered to be different if there exists a hole such that different types of villains are present in that hole in the arrangements.

Input

The first line contains a string s (2 ≤ |s| ≤ 10^{5}), representing the initial colony arrangement. String s can have both lowercase and uppercase English letters and its length is even.

The second line contains a single integer q (1 ≤ q ≤ 10^{5}) — the number of questions.

The i-th of the next q lines contains two integers x_i and y_i (1 ≤ x_i, y_i ≤ |s|, x_i ≠ y_i) — the two numbers given to the Jarvis for the i-th question.

Output

For each question output the number of arrangements possible modulo 10^9+7.

Examples

Input


abba
2
1 4
1 2


Output


2
0


Input


AAaa
2
1 2
1 3


Output


2
0


Input


abcd
1
1 3


Output


8

Note

Consider the first example. For the first question, the possible arrangements are "aabb" and "bbaa", and for the second question, index 1 contains 'a' and index 2 contains 'b' and there is no valid arrangement in which all 'a' and 'b' are in the same half.

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
const int mod = 1000000007;
struct Mod {
 public:
  int num;
  Mod() : Mod(0) { ; }
  Mod(long long int n) : num((n % mod + mod) % mod) {
    static_assert(mod < INT_MAX / 2,
                  "mod is too big, please make num 'long long int' from 'int'");
  }
  Mod(int n) : Mod(static_cast<long long int>(n)) { ; }
  operator int() { return num; }
};
Mod operator+(const Mod a, const Mod b) { return Mod((a.num + b.num) % mod); }
Mod operator+(const long long int a, const Mod b) { return Mod(a) + b; }
Mod operator+(const Mod a, const long long int b) { return b + a; }
Mod operator++(Mod &a) { return a + Mod(1); }
Mod operator-(const Mod a, const Mod b) {
  return Mod((mod + a.num - b.num) % mod);
}
Mod operator-(const long long int a, const Mod b) { return Mod(a) - b; }
Mod operator--(Mod &a) { return a - Mod(1); }
Mod operator*(const Mod a, const Mod b) {
  return Mod(((long long)a.num * b.num) % mod);
}
Mod operator*(const long long int a, const Mod b) { return Mod(a) * b; }
Mod operator*(const Mod a, const long long int b) { return Mod(b) * a; }
Mod operator*(const Mod a, const int b) { return Mod(b) * a; }
Mod operator+=(Mod &a, const Mod b) { return a = a + b; }
Mod operator+=(long long int &a, const Mod b) { return a = a + b; }
Mod operator-=(Mod &a, const Mod b) { return a = a - b; }
Mod operator-=(long long int &a, const Mod b) { return a = a - b; }
Mod operator*=(Mod &a, const Mod b) { return a = a * b; }
Mod operator*=(long long int &a, const Mod b) { return a = a * b; }
Mod operator*=(Mod &a, const long long int &b) { return a = a * b; }
Mod operator^(const Mod a, const int n) {
  if (n == 0) return Mod(1);
  Mod res = (a * a) ^ (n / 2);
  if (n % 2) res = res * a;
  return res;
}
Mod mod_pow(const Mod a, const long long int n) {
  if (n == 0) return Mod(1);
  Mod res = mod_pow((a * a), (n / 2));
  if (n % 2) res = res * a;
  return res;
}
Mod inv(const Mod a) { return a ^ (mod - 2); }
Mod operator/(const Mod a, const Mod b) {
  assert(b.num != 0);
  return a * inv(b);
}
Mod operator/(const long long int a, const Mod b) { return Mod(a) / b; }
Mod operator/=(Mod &a, const Mod b) { return a = a / b; }
Mod fact[102400], factinv[102400];
void init(const int amax = 102400) {
  fact[0] = Mod(1);
  factinv[0] = 1;
  for (int i = 0; i < amax - 1; ++i) {
    fact[i + 1] = fact[i] * Mod(i + 1);
    factinv[i + 1] = factinv[i] / Mod(i + 1);
  }
}
Mod comb(const int a, const int b) {
  return fact[a] * factinv[b] * factinv[a - b];
}
int to_num(char ch) {
  int num;
  if ('a' <= ch && ch <= 'z') {
    num = 0 + (ch - 'a');
  } else {
    num = 26 + (ch - 'A');
  }
  return num;
}
vector<int> to_v(string &st) {
  vector<int> v(52);
  for (int i = 0; i < st.size(); ++i) {
    char ch(st[i]);
    v[to_num(ch)]++;
  }
  return v;
}
void sub(vector<long long int> &dp, int x) {
  vector<long long int> ans_dp(dp.size());
  for (int i = 0; i < dp.size(); ++i) {
    if (i + x < dp.size()) {
      dp[i + x] -= dp[i];
      if (dp[i + x] < 0) dp[i + x] += mod;
    }
  }
}
const int MAX_S = 100001;
int main() {
  init();
  vector<int> v(52);
  string st;
  int N = 0;
  {
    char chs[100010];
    scanf("%s", chs);
    st = chs;
    N = st.size();
    v = to_v(st);
  }
  vector<long long int> dp(MAX_S + 1);
  {
    vector<vector<long long int>> dps(2, vector<long long int>(MAX_S + 1));
    dps[0][0] = 1;
    for (int ch = 0; ch < 52; ++ch) {
      int cur = ch & 1;
      int tar = !cur;
      for (int l_cnt = 0; l_cnt <= MAX_S; ++l_cnt) {
        dps[tar][l_cnt] += dps[cur][l_cnt];
        if (dps[tar][l_cnt] >= mod) dps[tar][l_cnt] -= mod;
        if (v[ch] && l_cnt + v[ch] <= MAX_S) {
          dps[tar][l_cnt + v[ch]] += dps[cur][l_cnt];
          if (dps[tar][l_cnt + v[ch]] >= mod) dps[tar][l_cnt + v[ch]] -= mod;
        }
      }
      for (int l_cnt = 0; l_cnt <= MAX_S; ++l_cnt) {
        dps[cur][l_cnt] = 0;
      }
    }
    dp = dps[0];
  }
  Mod ini = fact[N / 2] * fact[N / 2];
  for (int i = 0; i < 52; ++i) {
    if (v[i]) ini /= fact[v[i]];
  }
  vector<vector<long long int>> answers(52, vector<long long int>(52));
  for (int a = 0; a < 52; ++a) {
    for (int b = a; b < 52; ++b) {
      if (a == b) {
        answers[a][b] = dp[N / 2];
      } else {
        vector<long long int> ini_dp(dp);
        int x = N / 2 - v[a] - v[b];
        sub(ini_dp, v[a]);
        sub(ini_dp, v[b]);
        answers[a][b] = ini_dp[N / 2];
        if (N / 2 - v[a] - v[b] >= 0)
          answers[a][b] += ini_dp[N / 2 - v[a] - v[b]];
        answers[a][b] %= mod;
      }
    }
  }
  int Q;
  cin >> Q;
  while (Q--) {
    int x, y;
    scanf("%d %d", &x, &y);
    x--;
    y--;
    int x_num = to_num(st[x]);
    int y_num = to_num(st[y]);
    if (x_num > y_num) swap(x_num, y_num);
    long long int answer = answers[x_num][y_num];
    answer *= ini.num;
    answer %= mod;
    printf("%lld\n", answer);
  }
  return 0;
}