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 JAVA):

Solution:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Vadim
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        r537D solver = new r537D();
        solver.solve(1, in, out);
        out.close();
    }

    static class r537D {
        int ind(char c) {
            if (c > 'Z')
                return 26 + (c - 'a');
            else
                return (c - 'A');
        }

        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            String s = in.ns();
            int[] cnt = new int[52];
            int n = s.length();
            for (int i = 0; i < n; i++) {
                int ind = ind(s.charAt(i));
                cnt[ind]++;
            }
            long mod = (int) 1e9 + 7;


            long[] inv = new long[n / 2 + 1];
            inv[1] = 1;
            int modInt = (int) mod;
            for (int i = 2; i <= n / 2; i++) {
                inv[i] = (mod - (mod / i) * inv[modInt % i] % mod) % mod;
            }
            long[] fact = new long[n / 2 + 1];
            long[] invFact = new long[n / 2 + 1];
            fact[1] = invFact[1] = 1;
            for (int i = 2; i <= n / 2; i++) {
                fact[i] = i * fact[i - 1] % mod;
                invFact[i] = invFact[i - 1] * inv[i] % mod;
            }

            long choice = fact[n / 2] * fact[n / 2] % mod;
            for (int i = 0; i < 52; i++) {
                if (cnt[i] > 0) {
                    choice = choice * invFact[cnt[i]] % mod;
                }
            }
            //System.out.println("choice = " + choice);

            long[] cur = new long[n / 2 + 7];
            long[] nxt = new long[n / 2 + 7];
            nxt[0] = cur[0] = 1;
            for (int i = 0; i < 52; i++) {
                if (cnt[i] > 0) {
                    for (int j = 0; j <= n / 2 - cnt[i]; j++) {
                        nxt[j + cnt[i]] = (nxt[j + cnt[i]] + cur[j]) % mod;
                    }
                    long[] tmp = cur;
                    cur = nxt;
                    nxt = tmp;
                    System.arraycopy(cur, 0, nxt, 0, n / 2 + 7);
                }
            }
            //System.out.println("nxt[n/2] = " + nxt[n / 2]);

            long[][] ans = new long[52][52];
            for (int i = 0; i < 52; i++) {
                for (int j = i; j < 52; j++) {
                    if (cnt[i] == 0 && cnt[j] == 0)
                        continue;
                    long[] dp = Arrays.copyOf(nxt, n / 2 + 1);
                    if (cnt[i] > 0) {
                        for (int k = cnt[i]; k <= n / 2; k++) {
                            dp[k] = (dp[k] - dp[k - cnt[i]] + mod) % mod;
                        }
                    }
                    if (cnt[j] > 0 && i != j) {
                        for (int k = cnt[j]; k <= n / 2; k++) {
                            dp[k] = (dp[k] - dp[k - cnt[j]] + mod) % mod;
                        }
                    }
                    ans[i][j] = dp[n / 2];
                }
            }


            int q = in.ni();
            for (int i = 0; i < q; i++) {
                int x = ind(s.charAt(in.ni() - 1));
                int y = ind(s.charAt(in.ni() - 1));
                if (x <= y) {
                    out.println(2 * ans[x][y] * choice % mod);
                } else
                    out.println(2 * ans[y][x] * choice % mod);
            }

        }

    }

    static class FastScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public FastScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String ns() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

        public int ni() {
            return Integer.parseInt(ns());
        }

    }
}