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>
using namespace std;
const long long mod = 1000 * 1000 * 1000 + 7;
long long binpow(long long a, long long b) {
  if (b == 0) {
    return 1;
  }
  if (b % 2 == 0) {
    return binpow((a * a) % mod, b / 2);
  } else {
    return (a * binpow((a * a) % mod, b / 2)) % mod;
  }
}
long long inverse(long long a) { return binpow(a, mod - 2); }
const int maxn = 100111;
long long inv[maxn];
inline long long sub(long long a, long long b) {
  return a >= b ? a - b : a + mod - b;
}
long long dp[maxn];
long long f['Z' + 'z' + 1]['Z' + 'z' + 1];
inline void propagateDp(long long x) {
  for (int j = maxn - 1; j >= 0; j--) {
    if (j + x < maxn) {
      dp[j + x] += dp[j];
      if (dp[j + x] >= mod) {
        dp[j + x] -= mod;
      }
    }
  }
}
inline void undoDp(long long x) {
  for (int we = 0; we < maxn; we++) {
    if (we >= x) {
      dp[we] = sub(dp[we], dp[we - x]);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  map<char, int> mp;
  for (int i = 0; i < s.length(); i++) {
    mp[s[i]]++;
  }
  vector<int> occurs;
  vector<char> chars;
  for (auto it : mp) {
    occurs.push_back(it.second);
    chars.push_back(it.first);
  }
  for (int i = 1; i < maxn; i++) {
    inv[i] = inverse(i);
  }
  dp[0] = 1;
  for (int i = 0; i < occurs.size(); i++) {
    propagateDp(occurs[i]);
  }
  long long W = 1;
  for (int i = 1; i <= s.length() / 2; i++) {
    W *= i;
    W %= mod;
    W *= i;
    W %= mod;
  }
  for (int i = 0; i < occurs.size(); i++) {
    for (int j = 1; j <= occurs[i]; j++) {
      W *= inv[j];
      W %= mod;
    }
  }
  for (int i = 0; i < chars.size(); i++) {
    undoDp(occurs[i]);
    for (int j = i + 1; j < chars.size(); j++) {
      undoDp(occurs[j]);
      if (occurs[i] <= s.length() / 2) {
        f[i][j] = f[j][i] = dp[s.length() / 2 - occurs[i]];
      }
      propagateDp(occurs[j]);
    }
    propagateDp(occurs[i]);
  }
  long long baseAns = dp[s.length() / 2];
  baseAns %= mod;
  baseAns *= W;
  baseAns %= mod;
  int q;
  cin >> q;
  for (int test = 0; test < q; test++) {
    int w, e;
    cin >> w >> e;
    w--;
    e--;
    char ch1 = s[w];
    char ch2 = s[e];
    int id1 = find(chars.begin(), chars.end(), ch1) - chars.begin();
    int id2 = find(chars.begin(), chars.end(), ch2) - chars.begin();
    if (id1 == id2) {
      cout << baseAns;
    } else {
      long long bad = f[id1][id2];
      bad *= 2;
      bad %= mod;
      bad *= W;
      bad %= mod;
      cout << sub(baseAns, bad);
    }
    cout << endl;
  }
  return 0;
}