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;
pair<long long, pair<long long, long long> > gcd(long long, long long);
const long long modlo = 1000000007;
int n, m, tar;
char inp[200000];
int len[256];
long long factr[50005], base;
bool ans_f[256][256];
long long ans_t[256][256], ans;
long long dp_t[50005], dp_tt[50005];
void ins(int len, bool flag) {
  if (flag)
    for (int i = tar - len; i >= 0; i--)
      dp_t[i + len] = (dp_t[i + len] + dp_t[i]) % modlo;
  else
    for (int i = 0; i <= tar - len; i++)
      dp_t[i + len] = (dp_t[i + len] - dp_t[i] + modlo) % modlo;
}
int main() {
  int i, j, k;
  long long tmp;
  scanf("%s", inp);
  for (n = 0; inp[n]; n++) len[inp[n]]++;
  tar = n / 2;
  factr[0] = 1LL;
  for (i = 1; i <= tar; i++) factr[i] = (factr[i - 1] * i) % modlo;
  base = (factr[tar] * factr[tar]) % modlo;
  dp_t[0] = 1LL;
  for (i = 0; i < 256; i++) {
    if (!len[i]) continue;
    ins(len[i], true);
    tmp = (gcd(modlo, factr[len[i]]).second.second % modlo) + modlo;
    base = (base * tmp) % modlo;
  }
  ans = (dp_t[tar] * base) % modlo;
  memcpy(dp_tt, dp_t, sizeof(long long) * (tar + 1));
  scanf("%d", &k);
  while (k--) {
    scanf("%d %d", &i, &j);
    if (inp[i - 1] == inp[j - 1])
      ans_t[inp[i - 1]][inp[j - 1]] = ans;
    else if (!ans_f[inp[i - 1]][inp[j - 1]]) {
      ins(len[inp[i - 1]], false);
      ins(len[inp[j - 1]], false);
      tmp = (dp_t[tar - len[inp[i - 1]] - len[inp[j - 1]]] * 2LL) % modlo;
      tmp = (tmp * base) % modlo;
      memcpy(dp_t, dp_tt, sizeof(long long) * (tar + 1));
      ans_f[inp[i - 1]][inp[j - 1]] = ans_f[inp[j - 1]][inp[i - 1]] = true;
      ans_t[inp[i - 1]][inp[j - 1]] = ans_t[inp[j - 1]][inp[i - 1]] = tmp;
    }
    printf("%I64d\n", ans_t[inp[i - 1]][inp[j - 1]]);
  }
  return 0;
}
pair<long long, pair<long long, long long> > gcd(long long a, long long b) {
  long long sa = 1, sb = 0;
  long long ta = 0, tb = 1;
  long long q, r, sr, tr;
  while (b) {
    q = a / b;
    r = a - b * q;
    sr = sa - sb * q;
    tr = ta - tb * q;
    a = b, b = r;
    sa = sb, sb = sr;
    ta = tb, tb = tr;
  }
  return {a, {sa, ta}};
}