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 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;
}