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.*;
import java.util.*;
public class  Main{
	static int mod=(int)1e9+7;
	static long fastpow(long n,long ti) {
		 if (ti == 0) 
		        return 1l;
		if(ti%2==0) {
			long y=fastpow(n, ti/2);
			long k=y*y;
			k%=mod;
			return k;
		}
		else {
			long y=fastpow(n, ti/2);
			long k=((n*y)%mod)*y;
			k%=mod;
			return k;
		}
	}
	static long modInv(long x) {
		return fastpow(x, mod-2);
	}
	public static void main(String[] args) throws Exception{
		MScanner sc=new MScanner(System.in);
		PrintWriter pw=new PrintWriter(System.out);
		char[]in=sc.nextLine().toCharArray();
		int n=in.length;
		int[]freq=new int[52];
		for(char c:in) {
			int cur;
			if(c<='Z') {
				cur=c-'A';
				cur+=26;
			}
			else {
				cur=c-'a';
			}
			freq[cur]++;
		}
		int[]dp=new int[(n/2)+1];
		dp[0]=1;
		for(int i=0;i<52;i++){
			if(freq[i]==0)continue;
			for(int j=n/2;j>=freq[i];j--) {
				dp[j]+=dp[j-freq[i]];
				dp[j]%=mod;
			}
		        	
		}
		
		long[]fac=new long[n+1];
		fac[0]=1;for(int i=1;i<=n;i++)fac[i]=(fac[i-1]*i)%mod;
		
		long goodString=(fac[n/2]*fac[n/2])%mod;
		long mul=1;
		for(int i=0;i<52;i++) {
			mul=(mul*fac[freq[i]])%mod;
		}
		goodString=(goodString*modInv(mul))%mod;
		long[][]ans=new long[52][52];
		
		for(int c=0;c<52;c++) {
			ans[c][c]=(goodString*dp[n/2])%mod;
		}
		
		for(int c1=0;c1<52;c1++) {
			if(freq[c1]==0)continue;
			for(int i=freq[c1];i<=n/2;i++) {
				dp[i]-=dp[i-freq[c1]];
				dp[i]+=mod;
				dp[i]%=mod;
			}
			
			for(int c2=c1+1;c2<52;c2++) {
				if(freq[c2]==0)continue;
				for(int i=freq[c2];i<=n/2;i++) {
					dp[i]-=dp[i-freq[c2]];
					dp[i]+=mod;
					dp[i]%=mod;
				}
				
				ans[c1][c2]=ans[c2][c1]=(((dp[n/2]*2)%mod)*goodString)%mod;
				
				for(int i=n/2;i>=freq[c2];i--) {
					dp[i]+=dp[i-freq[c2]];
					dp[i]%=mod;
				}
			}
			
			for(int i=n/2;i>=freq[c1];i--) {
				dp[i]+=dp[i-freq[c1]];
				dp[i]%=mod;
			}
		}
		int q=sc.nextInt();
		while(q-->0) {
			int x=sc.nextInt()-1,y=sc.nextInt()-1;
			int c1,c2;
			
			if(in[x]<='Z') {
				c1=in[x]-'A';
				c1+=26;
			}
			else {
				c1=in[x]-'a';
			}
			
			if(in[y]<='Z') {
				c2=in[y]-'A';
				c2+=26;
			}
			else {
				c2=in[y]-'a';
			}
			
			pw.println(ans[c1][c2]);
		}
		pw.flush();
	}
	static class MScanner {
		StringTokenizer st;
		BufferedReader br;
		public MScanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}
 
		public MScanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}
 
		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public int[] intArr(int n) throws IOException {
	        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public long[] longArr(int n) throws IOException {
	        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public int[] intSortedArr(int n) throws IOException {
	        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        shuffle(in);
	        Arrays.sort(in);
	        return in;
		}
		public long[] longSortedArr(int n) throws IOException {
	        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        shuffle(in);
	        Arrays.sort(in);
	        return in;
		}
		static void shuffle(int[]in) {
			for(int i=0;i<in.length;i++) {
				int idx=(int)(Math.random()*in.length);
				int tmp=in[i];
				in[i]=in[idx];
				in[idx]=tmp;
			}
		}
		static void shuffle(long[]in) {
			for(int i=0;i<in.length;i++) {
				int idx=(int)(Math.random()*in.length);
				long tmp=in[i];
				in[i]=in[idx];
				in[idx]=tmp;
			}
		}
		public Integer[] IntegerArr(int n) throws IOException {
	        Integer[]in=new Integer[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public Long[] LongArr(int n) throws IOException {
	        Long[]in=new Long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public String nextLine() throws IOException {
			return br.readLine();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public char nextChar() throws IOException {
			return next().charAt(0);
		}
 
		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public boolean ready() throws IOException {
			return br.ready();
		}
 
		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
	static void addX(int[]in,int x) {
		for(int i=0;i<in.length;i++)in[i]+=x;
	}
	static void addX(long[]in,int x) {
		for(int i=0;i<in.length;i++)in[i]+=x;
	}
}