Nadeko's birthday is approaching! As she decorated the room for the party, a long garland of Dianthus-shaped paper pieces was placed on a prominent part of the wall. Brother Koyomi will like it!

Still unsatisfied with the garland, Nadeko decided to polish it again. The garland has n pieces numbered from 1 to n from left to right, and the i-th piece has a colour si, denoted by a lowercase English letter. Nadeko will repaint at most m of the pieces to give each of them an arbitrary new colour (still denoted by a lowercase English letter). After this work, she finds out all subsegments of the garland containing pieces of only colour c — Brother Koyomi's favourite one, and takes the length of the longest among them to be the Koyomity of the garland.

For instance, let's say the garland is represented by "kooomo", and Brother Koyomi's favourite colour is "o". Among all subsegments containing pieces of "o" only, "ooo" is the longest, with a length of 3. Thus the Koyomity of this garland equals 3.

But problem arises as Nadeko is unsure about Brother Koyomi's favourite colour, and has swaying ideas on the amount of work to do. She has q plans on this, each of which can be expressed as a pair of an integer mi and a lowercase letter ci, meanings of which are explained above. You are to find out the maximum Koyomity achievable after repainting the garland according to each plan.

Input

The first line of input contains a positive integer n (1 ≤ n ≤ 1 500) — the length of the garland.

The second line contains n lowercase English letters s1s2... sn as a string — the initial colours of paper pieces on the garland.

The third line contains a positive integer q (1 ≤ q ≤ 200 000) — the number of plans Nadeko has.

The next q lines describe one plan each: the i-th among them contains an integer mi (1 ≤ mi ≤ n) — the maximum amount of pieces to repaint, followed by a space, then by a lowercase English letter ci — Koyomi's possible favourite colour.

Output

Output q lines: for each work plan, output one line containing an integer — the largest Koyomity achievable after repainting the garland according to it.

Examples

Input

6
koyomi
3
1 o
4 o
4 m


Output

3
6
5


Input

15
yamatonadeshiko
10
1 a
2 a
3 a
4 a
5 a
1 b
2 b
3 b
4 b
5 b


Output

3
4
5
7
8
1
2
3
4
5


Input

10
aaaaaaaaaa
2
10 b
10 z


Output

10
10

Note

In the first sample, there are three plans: 

  * In the first plan, at most 1 piece can be repainted. Repainting the "y" piece to become "o" results in "kooomi", whose Koyomity of 3 is the best achievable; 
  * In the second plan, at most 4 pieces can be repainted, and "oooooo" results in a Koyomity of 6; 
  * In the third plan, at most 4 pieces can be repainted, and "mmmmmi" and "kmmmmm" both result in a Koyomity of 5. 
20
aaaaaaaaaaaaaaaaaaaa
1
11 a
 4
cbcc
12
4 b
4 c
1 b
2 a
3 b
2 c
4 a
1 a
2 b
3 a
1 c
3 c
 100
dddddccccdddddaaaaabbbbbbbbbbbbbaaacdcabbacccacccccbdbbadddbbddddbdaaccacdddbbbaddddbbbbdcbbbdddddda
50
54 b
48 d
45 b
52 c
52 a
48 a
54 b
45 a
47 d
50 d
53 a
34 a
51 b
48 d
47 d
47 a
48 d
53 b
52 d
54 d
46 a
38 a
52 b
49 a
49 b
46 c
54 a
45 b
35 c
55 c
51 c
46 d
54 d
50 a
33 c
46 a
50 b
50 a
54 a
32 b
55 b
49 c
53 d
49 a
46 b
48 c
47 b
47 b
47 a
46 b
 5
aaaaa
1
1 b
 4
ddbb
16
3 c
3 b
1 a
1 b
4 d
4 a
3 d
2 a
2 d
4 c
3 a
2 c
4 b
1 c
2 b
1 d
 4
abcc
24
1 c
4 d
3 c
1 d
1 c
1 b
3 b
2 c
3 d
3 d
4 c
2 a
4 d
1 a
1 b
4 a
4 d
3 b
4 b
3 c
3 a
2 d
1 a
2 b
 1
c
4
1 x
1 a
1 e
1 t
 40
cbbcbcccccacccccbbacbaabccbbabbaaaaacccc
10
40 a
28 c
25 c
21 a
18 c
27 a
9 c
37 c
15 a
18 b
 200
ddeecdbbbeeeeebbbbbaaaaaaaaaaaaaaaaaaaaaaabbcaacccbeeeeddddddddddddccccccdffeeeeecccccbbbbaaaaedfffffaadeeeeeeeedddddaaaaaaaaaaaaaabbbbbcaadddeefffbbbbcccccccccccbbbbbbeeeeeeeffffffdffffffffffffaaaaab
10
43 f
118 d
165 f
72 f
48 f
2 a
61 e
94 d
109 f
16 a

20
 4
4
2
2
4
4
4
1
3
3
4
4
 85
72
76
69
68
63
85
60
71
74
69
46
82
72
71
62
72
84
76
78
61
50
83
64
80
60
70
76
49
72
68
70
78
66
47
61
81
66
70
53
86
63
77
64
77
62
78
78
62
77
 1
 3
4
1
3
4
4
4
2
4
4
3
2
4
1
4
3
 3
4
4
1
3
2
4
4
3
3
4
3
4
2
2
4
4
4
4
4
4
2
2
3
 1
1
1
1
 40
40
40
31
35
37
23
40
24
27
 64
144
193
98
69
25
79
117
137
41

/*
 * DA-IICT
 * Author: Jugal Kalal
 */
import java.util.*;
import java.io.*;
import java.math.*;
public class Fuck{
//	static long MOD=(long)Math.pow(10,9)+7;
	static final int lint=Integer.MAX_VALUE;
	static final double ldouble=Double.MAX_VALUE;
	public static void main(String args[]) {
        new Thread(null, new Runnable() {
            public void run() {
                try{
                    solve();
                    w.close();
                }
                catch(Exception e){
                    e.printStackTrace();
                }
            }
        }, "1", 1 << 26).start();
	}
	static InputReader in;
    static PrintWriter w;
    static void solve(){
        in = new InputReader(System.in);
        w = new PrintWriter(System.out);
        int n=in.nextInt();
        String str=in.nextLine();
        HashMap<Character,ArrayList<Integer>> hmap=new HashMap<Character,ArrayList<Integer>>();
        for(char c='a';c<='z';c++){
        	ArrayList<Integer> arr=new ArrayList<Integer>();
        	for(int i=0;i<n;i++){
        		if(str.charAt(i)!=c){
        			arr.add(i);
        		}
        	}
        	hmap.put(c,arr);
        }
        int q=in.nextInt();
        while(q-->0){
        	String s[]=in.nextLine().split(" ");
        	int m=Integer.parseInt(s[0]);
        	char c=s[1].charAt(0);
        	int l=0,r=m;
        	int ans=Integer.MIN_VALUE;
        	for(int i=0;i<hmap.get(c).size();i++){
        		if(i!=0){
        			l=hmap.get(c).get(i-1);
        		}
        		if(i+m>=hmap.get(c).size()){
        			r=n+1;
        		}else{
        			r=hmap.get(c).get(i+m);
        		}
        		ans=Integer.max(ans, r-l-1);
        	}
        	if(ans==Integer.MIN_VALUE){
        		ans=n;
        	}
        	w.println(ans);
        }
    }
    static void print(int c[],int n){
    	for(int i=0;i<n;i++){
        	w.print(c[i]);
        	if(i!=n-1){
        		w.print(" ");
        	}
        }
        w.println();
    }
    static boolean visited[];
    static ArrayList<Integer> adj[]; //Adjacency Lists
    static int V;   // No. of vertices
    // Constructor
    static void Graph(int v){
        V = v;
        visited=new boolean[v];
        adj = new ArrayList[v];
        for (int i=0; i<v; ++i){
        	adj[i] = new ArrayList();
        }
    }
    // Function to add an edge into the graph
    static void addEdge(int v,int w){
		adj[v].add(w);
		adj[w].add(v);
    }
    static void bfs(int s,int n){
    	LinkedList<Integer> queue=new LinkedList<Integer>();
    	LinkedList<Integer> lev=new LinkedList<Integer>();
    	lev.add(0);
    	queue.add(s);
    	visited[s]=true;
    	while(!queue.isEmpty()){
    		int num=queue.pop();
    		int l=lev.pop();
    		for(int i=0;i<adj[num].size();i++){
    			if(!visited[adj[num].get(i)]){
    				visited[adj[num].get(i)]=true;
    				queue.add(adj[num].get(i));
    				lev.add(l+1);
    			}
    		}
    	}
    	
    }
    class Comp implements Comparator<ArrayList<Integer>>{
        @Override
        public int compare(ArrayList<Integer> arr1,ArrayList<Integer> arr2){
        	int min=Integer.min(arr1.size(), arr2.size());
            for(int i=0;i<min;i++){
            	if(arr1.get(i)>arr2.get(i)){
            		return 1;
            	}
            	if(arr1.get(i)<arr2.get(i)){
            		return -1;
            	}
            }
            if(arr1.size()>arr2.size()){
            	return 1;
            }
            if(arr1.size()<arr2.size()){
            	return -1;
            }
            return 0;
        }
    }
    static long power(long base, long exponent, long modulus){
	    long result = 1L;
	    while (exponent > 0) {
	        if (exponent % 2L == 1L)
	            result = (result * base) % modulus;
	        exponent = exponent >> 1;
	        base = (base * base) % modulus;
	    }
	    return result;
	}
    static HashMap<Long,Long> primeFactors(long n){
        HashMap<Long,Long> ans=new HashMap<Long,Long>();
    	// Print the number of 2s that divide n
        while (n%2L==0L)
        {
            if(ans.containsKey(2L)){
            	ans.put(2L,ans.get(2L)+1L);
            }else{
            	ans.put(2L,1L);
            }
            n /= 2L;
        }
 
        // n must be odd at this point.  So we can
        // skip one element (Note i = i +2)
        for (long i = 3; i <= Math.sqrt(n); i+= 2L)
        {
            // While i divides n, print i and divide n
            while (n%i == 0)
            {
            	if(ans.containsKey(i)){
                	ans.put(i,ans.get(i)+1L);
                }else{
                	ans.put(i,1L);
                }
                n /= i;
            }
        }
 
        // This condition is to handle the case whien
        // n is a prime number greater than 2
        if (n > 2)
            ans.put(n,1L);
        return ans;
    }
//	static long gcd(long a,long b){
//		if(a==0){
//			return b;
//		}
//		return gcd(b%a,a);
//	}
	static boolean isPrime[];
////for marking all prime numbers greater than 1 and less than equal to N
	static void sieve(int N) {
	 isPrime=new boolean[N+1];
	 isPrime[0] = true;
	 isPrime[1] = true;
	 for(int i = 2; i * i <= N; ++i) {
	      if(isPrime[i] == false) {//Mark all the multiples of i as composite numbers
	          for(int j = i * i; j <= N ;j += i)
	              isPrime[j] = true;
	     }
	 }
	}
//  //if  str2 (pattern) is subsequence of str1 (Text) or not
//	static boolean function(String str1,String str2){
//	     str2 = str2.replace("", ".*");  //returns .*a.*n.*n.*a.
//	     return (str1.matches(str2));  // returns true
//	}
    static int Arr[];
    static long size[];
  //modified initialize function:
    static void initialize(int N){
    	Arr=new int[N];
    	size=new long[N];
        for(int i = 0;i<N;i++){
        	Arr[ i ] = i ;
        	size[ i ] = 1;
        }
    }
    static boolean find(int A,int B){
        if( root(A)==root(B) )       //if A and B have same root,means they are connected.
        return true;
        else
        return false;
    }
 // modified root function.
    static void weighted_union(int A,int B,int n){
        int root_A = root(A);
        int root_B = root(B);
        if(size[root_A] < size[root_B ]){
        	Arr[ root_A ] = Arr[root_B];
        	size[root_B] += size[root_A];
        }
        else{
        	Arr[ root_B ] = Arr[root_A];
        	size[root_A] += size[root_B];
        }
    }
    static int root (int i){
        while(Arr[ i ] != i){
            Arr[ i ] = Arr[ Arr[ i ] ] ; 
            i = Arr[ i ]; 
        }
        return i;
    }
    
 
	static boolean isPrime(long n) {
		if(n < 2L) return false;
		if(n == 2L || n == 3L) return true;
		if(n%2L == 0 || n%3L == 0) return false;	
		long sqrtN = (long)Math.sqrt(n)+1L;
		for(long i = 6L; i <= sqrtN; i += 6L) {
			if(n%(i-1) == 0 || n%(i+1) == 0) return false;
		}
		return true;
	}
//	static boolean T[][][];
//	static void subsetSum(int input[], int total, int count) {
//        T = new boolean[input.length + 1][total + 1][count+1];
//        for (int i = 0; i <= input.length; i++) {
//        	T[i][0][0] = true;
//        	for(int j = 1; j<=count; j++){
//        		T[i][0][j] = false;
//        	}
//        }
//        int sum[]=new int[input.length+1];
//        for(int i=1;i<=input.length;i++){
//            sum[i]=sum[i-1]+input[i-1];
//        }
//        for (int i = 1; i <= input.length; i++) {
//            for (int j = 1; j <= (int)Math.min(total,sum[i]); j++) {
//            	for (int k = 1; k <= (int)Math.min(i,count); k++){
//            		 if (j >= input[i - 1]) {//Exclude and Include
//                         T[i][j][k] = T[i - 1][j][k] || T[i - 1][j - input[i - 1]][k-1];
//                     } else {
//                         T[i][j][k] = T[i-1][j][k];
//                     }
//            	}
//            }
//        }
//    }
//	static <K,V extends Comparable<? super V>>
//	SortedSet<Map.Entry<K,V>> entriesSortedByValues(Map<K,V> map) {
//	    SortedSet<Map.Entry<K,V>> sortedEntries = new TreeSet<Map.Entry<K,V>>(
//	        new Comparator<Map.Entry<K,V>>() {
//	            @Override public int compare(Map.Entry<K,V> e1, Map.Entry<K,V> e2) {
//	                int res = e2.getValue().compareTo(e1.getValue());
//	                return res != 0 ? res : 1;
//	            }
//	        }
//	    );
//	    sortedEntries.addAll(map.entrySet());
//	    return sortedEntries;
//	}
	
 
	 
	//minimum prime factor of all the numbers less than n
    static int minPrime[];
	static void minimumPrime(int n){
		minPrime=new int[n+1];
		minPrime[1]=1;
        for (int i = 2; i * i <= n; ++i) {
            if (minPrime[i] == 0) {         //If i is prime
                for (int j = i * i; j <= n; j += i) {
                    if (minPrime[j] == 0) {
                        minPrime[j] = i;
                    }
                }
            }
        }
        for (int i = 2; i <= n; ++i) {
            if (minPrime[i] == 0) {
                minPrime[i] = i;
            }
        }
	}
	static long modInverse(long A, long M)
	{
		long x=extendedEuclid(A,M)[0];
		return (x%M+M)%M;    //x may be negative
	}
	static long[] extendedEuclid(long A, long B) {
		if(B == 0) {
			long d = A;
			long x = 1;
			long y = 0;
			return new long[]{x,y,d};
		}
		else {
			long arr[]=extendedEuclid(B, A%B);
			long temp = arr[0];
			arr[0] = arr[1];
			arr[1] = temp - (A/B)*arr[1];
			return arr;
		}
	}
 
	static class InputReader {
        private final InputStream stream;
        private final byte[] buf = new byte[8192];
        private int curChar, numChars;
        private SpaceCharFilter filter;
 
        public InputReader(InputStream stream) {
            this.stream = stream;
        }
        
        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }
 
        public String nextLine() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isEndOfLine(c));
            return res.toString();
        }
 
        public String readString() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }
 
        public long nextLong() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }
 
        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }
 
        public int[] nextIntArray(int n) {
            int[] arr = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = nextInt();
            }
            return arr;
        }
 
        public long[] nextLongArray(int n) {
            long[] arr = new long[n];
            for (int i = 0; i < n; i++) {
                arr[i] = nextLong();
            }
            return arr;
        }
 
        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }
 
        private boolean isEndOfLine(int c) {
            return c == '\n' || c == '\r' || c == -1;
        }
        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
	}
}
//class Pair {
//	int x,y,z;
//
//    Pair(int x,int y,int z){
//        this.x=x;
//        this.y=y;
//        this.z=z;
//    }
//	public int hashCode() {
//		final int prime = 31;
//		int result = 1;
//		result = prime * result + x;
//		result = prime * result + y;
//		result = prime * result + z;
//		return result;
//	}
//
//	public boolean equals(Object obj) {
//		if (this == obj)
//			return true;
//		if (obj == null)
//			return false;
//		if (getClass() != obj.getClass())
//			return false;
//		Pair other = (Pair) obj;
//		if (x != other.x)
//			return false;
//		if (y != other.y)
//			return false;
//		if (z != other.z)
//			return false;
//		return true;
//	}
//} 