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





public class Main {
    
    
    static class sort implements Comparator<List<Integer>>
   {
        public int compare(List<Integer>  a,List<Integer> b)
        {
            
            return (a.size() - b.size());
        }
   }
    
   /*static class sort implements Comparator<int[]>
   {
        public int compare(int[] a,int[] b)
        {
            
            return -b[0]+a[0];
        }
   }*/
   static class sort1 implements Comparator<long[]>
   {
        public int compare(long[] a,long[] b)
        {
            
          long c = -(a[0]-a[1]) + (b[0]-b[1]);

          if(c==0l) return 0;
          if(c>0l) return 1;
          return -1;
        }
   }
  
   static class sort11 implements Comparator<double[]>
   {
        public int compare(double[] a,double[] b)
        {
            //if(a[0] == b[0]) return a[1]-b[1];
           if(a[1] < b[1]) return -1;
           else if(a[1] > b[1]) return 1;
           return 0;
        }
   }
   public static String[] F(BufferedReader bf) throws Exception
    {
        return (bf.readLine().split(" "));
    }
    
   public static void pr(PrintWriter out,Object o)
   {
      
    out.println(o.toString());//out.flush();
    
   }
   public static void prW(PrintWriter out,Object o)
   {
      
    out.print(o.toString());//out.flush();
    
   }
   public static int intIn(String st)
   {
      return Integer.parseInt(st);
   }
   
   
    
    public static void pr(Object o)
    {
        System.out.println(o.toString());
    }
    public static void prW(Object o)
    {
        System.out.print(o.toString());
    }
    
   
    public static int inInt(String s)
    {
        return Integer.parseInt(s);
    }
    public static long in(String s)
    {
        return Long.parseLong(s);
    }
 
 
    static int[] toIntArray(String[] m) 
    { 
        int[] p=new int[m.length];
        for(int o=0;o<m.length;o++)
        {
            p[o]= inInt(m[o]);
        }
        return p;
    }
    static double[] toDArray(String[] m) 
    { 
        double[] p=new double[m.length];
        for(int o=0;o<m.length;o++)
        {
            p[o]= Double.parseDouble(m[o]);
        }
        return p;
    }
    static long[] toLArray(String[] m) 
    { 
       long[] p=new long[m.length];
        for(int o=0;o<m.length;o++)
        {
            p[o]= in(m[o]);
        }
        return p;
    }
   
     static long gcd(long a, long b)
        {
          if (b == 0)
            return a;
          return gcd(b, a % b); 
        }
     
        static long pow(long x, long y, long p)
      {
        if(y == 0) return 1l;
        long res = 1; // Initialize result
     
        x = x % p; // Update x if it is more than or
        // equal to p
     
        if (x == 0)
          return 0l; // In case x is divisible by p;
     
        while (y > 0)
        {
     
          // If y is odd, multiply x with result
          if ((y & 1) != 0)
            res = (res * x) % p;
     
          // y must be even now
          y = y >> 1; // y = y/2
          x = (x * x) % p;
        }
        return res;
      }
    
   
    

   
   

   
    static long __gcd(long n1, long n2)
    {

        if(n1==0l) return n2;
        if(n2==0l) return n1;
        if(n1==1l || n2==1l) return 1l;
       // long gcd = 1;
        if(n1 == n2)  return n1;
        if(n1>n2) return __gcd(n1%n2,n2);
        return __gcd(n1,n2%n1);
        
    }
    
   
    
    public static boolean ok(int l,char[] arr,int[][] count,int v,int mid)
    {
        int i=0;int j=l-1;
        while(j<arr.length)
        {
            int c = count[j][v];
            if(i>0) c -= (count[i-1][v]);

            if((c+mid) >= (l)) return true;
            i++;j++;
        }

        return false;
    }
    public static void main (String[] args) throws Exception {
        
        BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);;;
        
        //int[] map=new int[1000001];
      
       int yy=1;//inInt(bf.readLine());
       


        //Long[][][] dp = new Long[100001][101][2];
        for(int w=0;w<yy;w++)
        {
             //String str = bf.readLine();
          out.flush();
         
            String[] xlp = bf.readLine().split(" ");
            //String st = bf.readLine();
        int n;//boolean bol=false;
           long  m;//long a,b,c;
          // int l;
           //int  k;//pr(out,"vbc");

         n=inInt(xlp[0]);//m=in(xlp[1]);//int ta=inInt(xlp[2]);int tb=inInt(xlp[3]);k=inInt(xlp[4]);

       char[] arr = bf.readLine().toCharArray();

       int t = inInt(bf.readLine());
       int[][] op=new int[26][n+1];
       //boolean[] bol = new boolean[26];
       int[][] count=new int[n][26];

       for(int i=0;i<n;i++)
       {
          if(i>0)
          {
            for(int j=0;j<26;j++)
              count[i][j]=count[i-1][j];
          }

          count[i][arr[i]-'a']++;
       }

       for(int i=0;i<26;i++)
       {
          for(int j=1;j<=n;j++)
          {
              int lo,hi;
              lo=1;hi=n;
              int res=1;
              while(lo < hi)
              {
                 int mid = (lo+hi)/2;


                 if(ok(mid,arr,count,i,j))
                 {
                   res = mid;
                   lo=mid+1;
                 }
                 else hi=mid-1;

              }
              int mid=lo;
              if(ok(mid,arr,count,i,j))
                 {
                   res = Math.max(res,mid);
                  
                 }

                 op[i][j] = res;


          }
       }
       for(int i=0;i<t;i++)
       {
          String[] st  = bf.readLine().split(" ");
          int va = inInt(st[0]);
          int pa = (st[1].charAt(0)-'a');
          pr(out,op[pa][va]);
       }

         
        





   }
    out.close();
   bf.close();//
}}


/*

10
6 4 3 9 5 2 1 10 8 7

Kickstart
 String rp;
            rp = "Case #"+(w+1)+": "+(n-ans)+" ";
static int[][] dir={{0,1},{1,0},{-1,0},{0,-1}};

static class SegmentTreeRMQ 
    { 
    int st[]; 
    int minVal(int x, int y) { 
        return (x > y) ? x : y; 
    } 
  
    
    int getMid(int s, int e) { 
        return s + (e - s) / 2; 
    } 
  
    
    int RMQUtil(int ss, int se, int qs, int qe, int index) 
    { 
        
        if (qs <= ss && qe >= se) 
            return st[index]; 
  
        // If segment of this node is outside the given range 
        if (se < qs || ss > qe) 
            return Integer.MIN_VALUE; 
  
        // If a part of this segment overlaps with the given range 
        int mid = getMid(ss, se); 
        return minVal(RMQUtil(ss, mid, qs, qe, 2 * index + 1), 
                RMQUtil(mid + 1, se, qs, qe, 2 * index + 2)); 
    } 
  
    // Return minimum of elements in range from index qs (query 
    // start) to qe (query end).  It mainly uses RMQUtil() 
    int RMQ(int n, int qs, int qe) 
    { 
        // Check for erroneous input values 
        
  
        return RMQUtil(0, n - 1, qs, qe, 0); 
    } 
  
    // A recursive function that constructs Segment Tree for 
    // array[ss..se]. si is index of current node in segment tree st 
    int constructSTUtil(int arr[], int ss, int se, int si) 
    { 
        // If there is one element in array, store it in current 
        //  node of segment tree and return 
        if (ss == se) { 
            st[si] = arr[ss]; 
            return arr[ss]; 
        } 
  
        // If there are more than one elements, then recur for left and 
        // right subtrees and store the minimum of two values in this node 
        int mid = getMid(ss, se); 
        st[si] = minVal(constructSTUtil(arr, ss, mid, si * 2 + 1), 
                constructSTUtil(arr, mid + 1, se, si * 2 + 2)); 
        return st[si]; 
    } 
  
    
    void con(int arr[]) 
    { 
        // Allocate memory for segment tree 
  
        //Height of segment tree 
        int n = (arr.length);
        int x = (int) (Math.ceil(Math.log(n) / Math.log(2))); 
  
        //Maximum size of segment tree 
        int max_size = 2 * (int) Math.pow(2, x) - 1; 
        st = new int[max_size]; // allocate memory 
  
        // Fill the allocated memory st 
        constructSTUtil(arr, 0, n - 1, 0); 
    }
    }
     static class DSU {
    
    int[] p;int[] sz;int op;int c;;
    int[] last;
    public void G(int n)
    {
        last=new int[n];
        p=new int[n];
        sz=new int[n];c=n;
        op=n;
        for(int h=0;h<n;h++)
        {
            sz[h]=1;p[h]=h;
            last[h]=h;
        }
    }
    public int find(int x)
    {
        int y=x;
        while(x!=p[x]) x=p[x];
        while(y!=p[y])
        {
            int tem=p[y];
            p[y]=x;y=tem;
        }
        return p[y];
    }
    public void union(int a,int b)
    {
        int x,y;
        x=find(a);y=find(b);
        if(x==y) return;
        if(sz[x]>sz[y])
        {
            p[y] = x;
            sz[x]+=sz[y];
            last[x]=Math.max(last[x],last[y]);
        }
        else
        {
            p[x]=y;sz[y]+=sz[x];
            last[y]=Math.max(last[y],last[x]);
        }
        c--;
        
    }}

    static long pow(long x, long y, long p)
      {
        long res = 1; // Initialize result
     
        x = x % p; // Update x if it is more than or
        // equal to p
     
        if (x == 0)
          return 0l; // In case x is divisible by p;
     
        while (y > 0)
        {
     
          // If y is odd, multiply x with result
          if ((y & 1) != 0)
            res = (res * x) % p;
     
          // y must be even now
          y = y >> 1; // y = y/2
          x = (x * x) % p;
        }
        return res;
      }
      static long gcd(long a, long b)
        {
          if (b == 0)
            return a;
          return gcd(b, a % b); 
        }
        static int gcd(int a, int b,int o)
        {
          if (b == 0)
            return a;
          return gcd(b, a % b,o); 
        }

Geometric median

public static double F(double[] x,double[] w)
    {
        double d1,d2;
        double S=0.00;
        for(double dp : w) S += dp;
        int k = 0;
        double sum = S - w[0]; // sum is the total weight of all `x[i] > x[k]`

        while(sum > S/2)
        {
            ++k;
            sum -= w[k];
        }
        d1=x[k];
        return d1;
        k = w.length-1;
       sum = S - w[k]; // sum is the total weight of all `x[i] > x[k]`

        while(sum > S/2)
        {
            --k;
            sum -= w[k];
        }
        d2=x[k];
        return new double[]{d1,d2};
    }
*/


