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

import java.text.DecimalFormat;
import java.util.*;
import java.io.*;
import java.math.*;

public class Main {
	public static long mod = (long) (1e9 + 7);
	static InputReader s;
	static PrintWriter out;
	public static void main(String args[]) {
		new Thread(null, new Runnable() {
			public void run() {
				try {
					solve();
					out.flush();
					out.close();
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		}, "1", 1 << 26).start();
	}

	public static void solve() throws IOException {
		s = new InputReader(System.in);
		OutputStream outputStream = System.out;
		out = new PrintWriter(outputStream);
		Scanner sc = new Scanner(System.in);
		int n = s.nextInt();
		String str = s.next();
		int store[][]= new int[26][n+1];	
		for(int i=97;i<=122;i++){
			int arr[]= new int[n];
			for(int j=0;j<n;j++){
				if(str.charAt(j)==i){
					arr[j] = 1;
				}
			}
			for(int j=1;j<=n;j++){
				ArrayList<Integer> cons = findZeroes(arr, j);
//				debug(cons);
				int tp[]= new int[n];
				System.arraycopy( arr, 0, tp, 0, n);
				for(int k=0;k<cons.size();k++){
					tp[cons.get(k)]=1;
				}
				store[i-97][j] = getMaxLength(tp, n);
				//System.out.println(store[0][2]);
			}
		}
		int q= s.nextInt();
		for(int i=0;i<q;i++){
			int x = s.nextInt();
			int y = s.next().charAt(0)-97;
			out.println(store[y][x]);
		}
	}

	static ArrayList<Integer> findZeroes(int arr[], int m)
    {
		ArrayList<Integer> cons = new ArrayList<>();
        // Left and right indexes of current window
        int wL = 0, wR = 0; 
      
        // Left index and size of the widest window 
        int bestL = 0, bestWindow = 0; 
      
        // Count of zeroes in current window
        int zeroCount = 0; 
      
        // While right boundary of current window doesn't cross 
        // right end
        while (wR < arr.length)
        {
            // If zero count of current window is less than m,
            // widen the window toward right
            if (zeroCount <= m)
            {
                if (arr[wR] == 0)
                  zeroCount++;
                wR++;
            }
      
            // If zero count of current window is more than m,
            // reduce the window from left
            if (zeroCount > m)
            {
                if (arr[wL] == 0)
                  zeroCount--;
                wL++;
            }
      
            // Update widest window if this window size is more
            if (wR-wL > bestWindow)
            {
                bestWindow = wR-wL;
                bestL = wL;
            }
        }
      
        // Print positions of zeroes in the widest window
        for (int i=0; i<bestWindow; i++)
        {
            if (arr[bestL+i] == 0){
            	cons.add(bestL+i);
            }
        }
        return cons;
    }
	
	static int getMaxLength(int arr[], int n)
	{
	    int count = 0; //intitialize count
	    int result = 0; //initialize max
	 
	    for (int i = 0; i < n; i++)
	    {
	        // Reset count when 0 is found
	        if (arr[i] == 0)
	            count = 0;
	 
	        // If 1 is found, increment count
	        // and update result if count becomes
	        // more.
	        else
	        {
	            count++;//increase count
	            result = Math.max(result, count);
	        }
	    }
	 
	    return result;
	}
	
	static long combinations(long n, long r) { // O(r)
		if (r == 0 || r == n)
			return 1;
		r = Math.min(r, n - r);
		long ans = n; // nC1=n;
		for (int i = 1; i < r; i++) {
			ans = (ans * (n - i));
			 ans= ans/(i+1);
//			ans = (ans * modulo(i + 1, mod - 2, mod)) % mod;
		}
		return ans;
	}

	static long modulo(long x, long y, long p) {
		long res = 1;
		x = x % p;

		while (y > 0) {
			if (y % 2 == 1)
				res = (res * x) % p;

			y = y >> 1;
			x = (x * x) % p;
		}
		return res;
	}

	static HashSet<Integer> primeFactors(int n) // O(sqrt(n))
	{
		// Print the number of 2s that divide n
		HashSet<Integer> arr = new HashSet<>();
		while (n % 2 == 0) {
			arr.add(2);
			n = n / 2;
		}

		// n must be odd at this point. So we can skip one element (Note i = i
		// +2)
		for (int i = 3; i <= Math.sqrt(n); i = i + 2) {
			// While i divides n, print i and divide n
			while (n % i == 0) {
				arr.add(i);
				n = n / i;
			}
		}
		// This condition is to handle the case when n is a prime number
		// greater than 2
		if (n > 2)
			arr.add(n);

		return arr;
	}

	public static long expo(long a, long b) {
		if (b == 0)
			return 1;
		if (b == 1)
			return a;
		if (b == 2)
			return a * a;

		if (b % 2 == 0) {
			return expo(expo(a, (b / 2)), 2);
		} else {
			return a * expo(expo(a, (b - 1) / 2), 2);
		}
	}

	static class Pair implements Comparable<Pair> {
		int a;
		int b;
		
		Pair(int aa, int bb) {
			a = aa;
			b = bb;
		}

		public int compareTo(Pair o) {
			int ans = Integer.compare(this.a, o.a);
			return ans;
			// return ans==0 ? -Integer.compare(this.b, o.b):ans;
			// if(Long.compare(this.x, o.x)!=0)
			// return -Long.compare(this.x, o.x);
			// else
			// return Long.compare(this.y, o.y);
			// return Integer.compare(this.x, o.x);
			// return Long.compare(this.x, o.x);
		}

//		public int hashCode() {
//			int hu = (int) (a ^ (a >>> 32));
//			int hv = (int) (b ^ (b >>> 32));
//			return 31 * hu + hv;
//		}

		//
		public boolean equals(Object o) {
			Pair other = (Pair) o;
			return a == other.a && b == other.b;
		}

		public String toString() {
			return "[x=" + a + ", y=" + b + "]";
		}

	}

	public static int[] sieve(int N) { // O(n*log(logn))
		int arr[] = new int[N + 1];
		for (int i = 2; i <= Math.sqrt(N); i++) {
			if (arr[i] == 0) {
				for (int j = i * i; j <= N; j = j + i) {
					arr[j] = 1;
				}
			}
		}
		return arr;
		// All the i for which arr[i]==0 are prime numbers.
	}

	static int gcd(int a, int b) { // O(logn)
		if (b == 0)
			return a;
		return gcd(b, a % b);
	}

	public static void debug(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}

	static void catalan_numbers(int n) {
		long catalan[] = new long[n + 1];
		catalan[1] = 1;
		for (int i = 2; i <= n; i++) {
			for (int j = 1; j <= i - 1; j++) {
				catalan[i] = catalan[i] + ((catalan[j]) * catalan[i - j]);
			}
		}
	}

	static final class InputReader {
		private final InputStream stream;
		private final byte[] buf = new byte[1024];
		private int curChar;
		private int Chars;

		public InputReader(InputStream stream) {
			this.stream = stream;
		}

		private int read() throws IOException {
			if (curChar >= Chars) {
				curChar = 0;
				Chars = stream.read(buf);
				if (Chars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public final int nextInt() throws IOException {
			return (int) nextLong();
		}

		public final long nextLong() throws IOException {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
				if (c == -1)
					throw new IOException();
			}
			boolean negative = false;
			if (c == '-') {
				negative = true;
				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 negative ? (-res) : (res);
		}

		public final int[] nextIntBrray(int size) throws IOException {
			int[] arr = new int[size];
			for (int i = 0; i < size; i++)
				arr[i] = nextInt();
			return arr;
		}

		public final String next() throws IOException {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.append((char) c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public final String nextLine() throws IOException {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.append((char) c);
				c = read();
			} while (c != '\n' && c != -1);
			return res.toString();
		}

		private boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}
	}
}