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.
import java.io.*;
import java.util.*;

public class D implements Runnable{
	public static void main (String[] args) {new Thread(null, new D(), "_cf", 1 << 28).start();}

	public void run() {
		FastScanner fs = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		System.err.println("");

		int[] map = new int[256];
		char[] str = fs.next().toCharArray();
		TreeSet<Character> set = new TreeSet<>();
		for(char c : str) set.add(c);
		int cnt = 0;
		while(!set.isEmpty()) map[set.pollFirst()] = cnt++;
		int[] freq = new int[cnt];
		for(char c : str) freq[map[c]]++;
		
		int n = str.length, MOD = (int)1e9+7;
		int[] ways = new int[n/2+1];
		ways[0] = 1;
		for(int i = 0; i < freq.length; i++) {
			for(int j = n/2; j >= 0; j--) if(ways[j] != 0) {
				if(j+freq[i] <= n/2) {
					ways[j+freq[i]] += ways[j];
					if(ways[j+freq[i]] >= MOD) ways[j+freq[i]] -= MOD;
				}
			}
		}
		
		int[] facts = new int[n+1];
		facts[0] = 1;
		for(int i = 1; i <= n; i++) {
			facts[i] = (int)((long)facts[i-1]*i%MOD);
		}
		int add = mult(facts[n/2], facts[n/2]);
		int den = facts[freq[0]];
		for(int i = 1; i < freq.length; i++) den = mult(den, facts[freq[i]]);
		den = fastPow(den, MOD-2);
		add = mult(add, den);
		
		boolean[][] done = new boolean[cnt][cnt];
		int[][] ans = new int[cnt][cnt];
		
		int base = mult(add, ways[n/2]);
		int q = fs.nextInt();
		while(q-->0) {
			int x = fs.nextInt()-1, y = fs.nextInt()-1;
			if(str[x] == str[y]) {
				out.println(base);
				continue;
			}
			
			if(str[x] > str[y]) {
				int t = x; x = y; y = t;
			}
			
			x = map[str[x]]; y = map[str[y]];
			if(done[x][y]) {
				out.println(ans[x][y]);
				continue;
			}
			
			done[x][y] = true;
			
			if(n/2 - freq[x] - freq[y] < 0) {
				ans[x][y] = 0;
				out.println(ans[x][y]);
				continue;
			}
			
			int[] dp = new int[n/2+1];
			for(int i = 0; i <= n/2; i++) dp[i] = ways[i];
			undo(dp, freq[x]);
			undo(dp, freq[y]);
			
			ans[x][y] = mult(2, mult(add, dp[n/2-freq[x]-freq[y]]));
			out.println(ans[x][y]);
		}
		
		out.close();
	}
	
	void undo(int[] dp, int size) {
		int MOD = (int)1e9+7;
		for(int i = 0; i < dp.length; i++) {
			if(i+size >= dp.length) break;
			dp[i+size] -= dp[i];
			if(dp[i+size] < 0) dp[i+size] += MOD;
		}
	}
	
	int mult(long a, long b) {
		int MOD = (int)1e9+7;
		a *= b;
		return (int)(a%MOD);
	}
	
	int fastPow(int base, int expo) {
		if(expo == 0) return 1;
		if(expo == 1) return base;
		if((expo&1) == 1) {
			return mult(base, fastPow(base, expo-1));
		}
		long ret = fastPow(base, expo/2);
		return mult(ret, ret);
	}
	
	class FastScanner {
		public int BS = 1<<16;
		public char NC = (char)0;
		byte[] buf = new byte[BS];
		int bId = 0, size = 0;
		char c = NC;
		double num = 1;
		BufferedInputStream in;

		public FastScanner() {
			in = new BufferedInputStream(System.in, BS);
		}

		public FastScanner(String s) throws FileNotFoundException {
			in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
		}

		public char nextChar(){
			while(bId==size) {
				try {
					size = in.read(buf);
				}catch(Exception e) {
					return NC;
				}                
				if(size==-1)return NC;
				bId=0;
			}
			return (char)buf[bId++];
		}

		public int nextInt() {
			return (int)nextLong();
		}

		public long nextLong() {
			num=1;
			boolean neg = false;
			if(c==NC)c=nextChar();
			for(;(c<'0' || c>'9'); c = nextChar()) {
				if(c=='-')neg=true;
			}
			long res = 0;
			for(; c>='0' && c <='9'; c=nextChar()) {
				res = (res<<3)+(res<<1)+c-'0';
				num*=10;
			}
			return neg?-res:res;
		}

		public double nextDouble() {
			double cur = nextLong();
			return c!='.' ? cur:cur+nextLong()/num;
		}

		public String next() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c>32) {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public String nextLine() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c!='\n') {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public boolean hasNext() {
			if(c>32)return true;
			while(true) {
				c=nextChar();
				if(c==NC)return false;
				else if(c>32)return true;
			}
		}
		
		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for(int i = 0; i < n; i++) res[i] = nextInt();
			return res;
		}
		
	}

}