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>
const int mod = 1e9 + 7;
long long int fast_pow(long long int n, long long int pow) {
  if (pow == 0) return 1;
  if (pow == 1) return n;
  long long int temp = fast_pow(n, pow / 2) % mod;
  if (pow % 2 == 0)
    return (temp % mod * temp % mod) % mod;
  else
    return (temp % mod * temp % mod * n % mod) % mod;
}
int map_char_to_index(char ch) {
  if (ch >= 'A' && ch <= 'Z')
    return ch - 'A';
  else
    return ch - 'a' + 26;
}
std::vector<int> get_frequency(const std::string& str) {
  std::vector<int> frequency(52, 0);
  int len = str.length();
  for (int i = 0; i < len; ++i) {
    int ix = map_char_to_index(str[i]);
    frequency[ix]++;
  }
  return frequency;
}
std::vector<int> compute_factorials(int n) {
  std::vector<int> factorials(n + 1, 0);
  factorials[0] = 1;
  for (int i = 1; i <= n; ++i)
    factorials[i] = (1LL * factorials[i - 1] * i) % mod;
  return factorials;
}
std::vector<int> compute_inv_factorials(int facn, int n) {
  std::vector<int> inv_factorials(n + 1, 0);
  inv_factorials[n] = fast_pow(facn, mod - 2);
  for (int i = n - 1; i >= 0; --i)
    inv_factorials[i] = (1LL * inv_factorials[i + 1] * (i + 1)) % mod;
  return inv_factorials;
}
std::vector<int> find_all_subset_sum_to_k(const std::vector<int>& frequency,
                                          const int weight) {
  std::vector<int> dp(weight + 1, 0);
  dp[0] = 1;
  for (int i = 0; i < 52; i++) {
    if (frequency[i] == 0) continue;
    for (int w = weight; w >= frequency[i]; --w) {
      dp[w] = (0LL + dp[w] + dp[w - frequency[i]]) % mod;
    }
  }
  return dp;
}
template <typename T1, typename T2>
void precompute(T1& combinations, T2& frequency, T2& dp, int weight) {
  for (int ch1 = 0; ch1 < 52; ++ch1) {
    if (frequency[ch1] == 0) continue;
    int weight1 = frequency[ch1];
    std::vector<int> temp(dp);
    for (int i = weight1; i <= weight; ++i) {
      temp[i] = temp[i] - temp[i - weight1];
      if (temp[i] < 0) temp[i] += mod;
    }
    for (int ch2 = ch1 + 1; ch2 < 52; ++ch2) {
      if (frequency[ch2] == 0) continue;
      int weight2 = frequency[ch2];
      for (int i = weight2; i <= weight; ++i) {
        temp[i] = temp[i] - temp[i - weight2];
        if (temp[i] < 0) temp[i] += mod;
      }
      combinations[ch1][ch2] = (2LL * temp[weight / 2]) % mod;
      combinations[ch2][ch1] = (2LL * temp[weight / 2]) % mod;
      for (int i = weight; i >= weight2; --i)
        temp[i] = (0LL + temp[i] + temp[i - weight2]) % mod;
    }
  }
}
int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(NULL);
  std::cout.tie(NULL);
  int n;
  std::string str;
  std::cin >> str;
  n = str.length();
  std::vector<int> factorials = compute_factorials(n);
  std::vector<int> inv_factorials = compute_inv_factorials(factorials[n], n);
  std::vector<int> frequency = get_frequency(str);
  std::vector<int> dp = find_all_subset_sum_to_k(frequency, n);
  std::vector<std::vector<int>> combinations(52, std::vector<int>(52, 0));
  for (int i = 0; i < 52; ++i) combinations[i][i] = dp[n / 2];
  long long int W = (1LL * factorials[n / 2] * factorials[n / 2]) % mod;
  for (int i = 0; i < 52; ++i) {
    if (frequency[i] == 0) continue;
    W = (1LL * W * inv_factorials[frequency[i]]) % mod;
  }
  precompute(combinations, frequency, dp, n);
  int queries;
  std::cin >> queries;
  for (int i = 0; i < queries; ++i) {
    int l, r;
    std::cin >> l >> r;
    int ch1 = map_char_to_index(str[l - 1]);
    int ch2 = map_char_to_index(str[r - 1]);
    std::cout << (1LL * W * combinations[ch1][ch2]) % mod << std::endl;
  }
  return 0;
}