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;
void OUT_TST(string s, istream_iterator<string> it) { cerr << s; }
template <typename T, typename... Args>
void OUT_TST(string s, istream_iterator<string> it, T a, Args... args) {
  cerr << *it << "=" << a << " ";
  OUT_TST(s, ++it, args...);
}
template <class T>
void rd(T& ret) {
  ret = 0;
  bool ok = 0, u = 0;
  for (;;) {
    int c = getchar();
    if (c >= '0' && c <= '9')
      ret = (ret << 3) + (ret << 1) + c - '0', ok = 1;
    else if (c == '-')
      u = 1;
    else if (ok) {
      if (u) ret *= -1;
      return;
    }
  }
}
long long powmod(long long p, long long n, long long mod) {
  long long ret = 1;
  for (; n; n >>= 1) {
    if (n & 1) ret = ret * p % mod;
    p = p * p % mod;
  }
  return ret;
}
template <class T>
bool chmin(T& a, const T& b) {
  return b < a ? a = b, 1 : 0;
}
template <class T>
bool chmax(T& a, const T& b) {
  return b > a ? a = b, 1 : 0;
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
const int N = (int)1e5 + 9;
const long long mod = (int)1e9 + 7;
template <int sz>
struct Comb {
  const long long mod = ::mod;
  long long *fac, *ifac, *inv;
  long long mem_fac[sz + 5], mem_ifac[sz + 5], mem_inv[sz + 5];
  Comb(long long* fa = 0, long long* ifa = 0, long long* iv = 0) {
    fac = fa ? fa : mem_fac;
    ifac = ifa ? ifa : mem_ifac;
    inv = iv ? iv : mem_inv;
    fac[0] = fac[1] = 1;
    ifac[0] = ifac[1] = 1;
    inv[0] = inv[1] = 1;
    for (int i = 2; i < sz; ++i) {
      fac[i] = i * fac[i - 1] % mod;
      inv[i] = (mod - mod / i) * inv[mod % i] % mod;
      ifac[i] = ifac[i - 1] * inv[i] % mod;
    }
  }
  long long C(long long n, long long m) {
    if (n < m) return 0;
    return (fac[n] * ifac[m] % mod) * ifac[n - m] % mod;
  }
  long long A(long long n, long long m) {
    if (n < m) return 0;
    return fac[n] * ifac[n - m] % mod;
  }
};
long long fac[N], fac_inv[N], inv[N];
Comb<N> comb(fac, fac_inv, inv);
int idx(char c) {
  if (c >= 'a' && c <= 'z') return c - 'a';
  return c - 'A' + 26;
}
void add(int& a, int b) {
  a += b;
  if (a >= mod) a -= mod;
}
void calc(int sp, int up, const vector<int>& cnt, vector<vector<int>>& dp) {
  for (int i = 0; i < 52; ++i) {
    for (int j = 0; j <= up; ++j) {
      dp[i][j] = 0;
    }
  }
  dp[0][0] = 1;
  if (sp != 0 && cnt[0] <= up && cnt[0] > 0) {
    dp[0][cnt[0]] = 1;
  }
  for (int i = 0; i < 51; ++i) {
    for (int j = 0; j <= up; ++j)
      if (dp[i][j] > 0) {
        add(dp[i + 1][j], dp[i][j]);
        if (i + 1 != sp && j + cnt[i + 1] <= up && cnt[i + 1] > 0) {
          add(dp[i + 1][j + cnt[i + 1]], dp[i][j]);
        }
      }
  }
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(nullptr);
  string s;
  cin >> s;
  int n = s.size();
  vector<int> cnt(52, 0);
  for (char c : s) {
    cnt[idx(c)]++;
  }
  vector<vector<int>> ans(52, vector<int>(52, 0));
  vector<vector<int>> pref(52, vector<int>(n / 2 + 1, 0));
  vector<vector<int>> suf(52, vector<int>(n / 2 + 1, 0));
  calc(-1, n / 2, cnt, pref);
  int ans_all = pref[51][n / 2];
  for (int i = 0; i < 52; ++i) {
    calc(i, n / 2, cnt, pref);
    reverse(cnt.begin(), cnt.end());
    calc(51 - i, n / 2, cnt, suf);
    reverse(cnt.begin(), cnt.end());
    auto get_value = [&](int a, int b, vector<vector<int>>& an) {
      if (a < 0 || a > 51) {
        if (b == 0) return 1;
        return 0;
      }
      return an[a][b];
    };
    for (int j = 0; j < 52; ++j) {
      if (i == j) continue;
      ans[i][j] = 0;
      for (int k = 0; k <= n / 2; ++k) {
        long long t1 = get_value(j - 1, k, pref),
                  t2 = get_value(50 - j, n / 2 - k, suf);
        add(ans[i][j], t1 * t2 % mod);
      }
    }
  }
  long long cons = fac[n / 2] % mod * fac[n / 2] % mod;
  for (int i = 0; i < 52; ++i) {
    cons = cons * fac_inv[cnt[i]] % mod;
  }
  long long cons2 = cons * 2ll % mod;
  ans_all = ans_all * cons % mod;
  for (int i = 0; i < 52; ++i) {
    for (int j = 0; j < 52; ++j) {
      ans[i][j] = ans[i][j] * cons2 % mod;
    }
  }
  int q;
  cin >> q;
  while (q--) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    int index1 = idx(s[a]), index2 = idx(s[b]);
    if (index1 == index2) {
      cout << ans_all << endl;
    } else {
      cout << ans[index1][index2] << endl;
    }
  }
  return 0;
}