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 s_{i}, 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 m_{i} and a lowercase letter c_{i}, 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 s_1s_2... s_{n} 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 m_{i} (1 ≤ m_{i} ≤ n) — the maximum amount of pieces to repaint, followed by a space, then by a lowercase English letter c_{i} — 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.

Difficulty: interview

Starter code:

Solutions:
import sys



n = int(sys.stdin.readline().strip())
s = sys.stdin.readline().strip()

dp = [[-1] * (n + 1) for i in range(26)]


for c in range(26):
    for j in range(n):
        tst = 1 if s[j] == chr(c + 97) else 0
        dp[c][1 - tst] = max(dp[c][1 - tst], 1)
        for k in range(j + 1, n):
            if s[k] == chr(c + 97):tst += 1
            dp[c][k - j + 1 - tst] = max(dp[c][k - j + 1 - tst], k - j + 1)

#for c in range(26):
#    for j in range(n):
#        dp[c][j + 1] = max(dp[c][j], dp[c][j + 1])

q = int(sys.stdin.readline().strip())

for i in range(q):
    m, c = [item for item in sys.stdin.readline().strip().split()]
    m = int(m)
    #print(max([dp[ord(c) - 97][u] for u in range(m + 1)]))
    print(dp[ord(c) - 97][m]) if dp[ord(c) - 97][m] != -1 else print(n)

import sys

def solve():
    n = int(sys.stdin.readline().rstrip())
    s = sys.stdin.readline().rstrip()
    q = int(sys.stdin.readline().rstrip())

    pfs = [[0]*(n + 1) for i in range(26)]
    for i in range(n):
        ch = ord(s[i]) - ord('a')

        for j in range(26):
            if j == ch:
                pfs[j][i + 1] = pfs[j][i] + 1
            else:
                pfs[j][i + 1] = pfs[j][i]

    '''
    for i in range(26):
        print(chr(i + ord('a')), *pfs[i])
    print()
    '''

    dp = [[0]*(n + 1) for i in range(26)]

    for c in range(26):
        for l in range(n + 1):
            for r in range(l, n + 1):
                tc = r - l - (pfs[c][r] - pfs[c][l])
                dp[c][tc] = max(dp[c][tc], r - l)

        for i in range(1, n + 1):
            dp[c][i] = max(dp[c][i], dp[c][i - 1])

    '''
    for i in range(26):
        print(chr(i + ord('a')), *dp[i])
    '''

    for qi in range(q):
        mi, ci = sys.stdin.readline().split()
        mi = int(mi)
        ci = ord(ci) - ord('a')
        ans = dp[ci][mi]
        print(ans)

def __starting_point():
    solve()
__starting_point()

import sys
n = int(sys.stdin.readline().strip())
s = sys.stdin.readline().strip()
ans = [[-1]*(n+1) for x in range(26)]

for c in range(26):
    for l in range(n):
        nrOfC = 0 
        for r in range(l, n):
            if s[r] == chr(97 + c):
                nrOfC += 1
            ans[c][r - l + 1 - nrOfC] = max(ans[c][r - l + 1 -nrOfC], r-l+1)

for i in range(int(sys.stdin.readline().strip())):
    m,c = sys.stdin.readline().strip().split()
    m = int(m)
    print(ans[ord(c) - 97][m] if ans[ord(c) - 97][m] != -1 else n)

import sys
n = int(sys.stdin.readline().strip())
s = sys.stdin.readline().strip()
ans = [[-1]*(n+1) for x in range(26)]

for c in range(26):
    for l in range(n):
        nrOfC = 0 
        for r in range(l, n):
            if s[r] == chr(97 + c):
                nrOfC += 1
            ans[c][r - l + 1 - nrOfC] = max(ans[c][r - l + 1 -nrOfC], r-l+1)

for i in range(int(sys.stdin.readline().strip())):
    m,c = sys.stdin.readline().strip().split()
    m = int(m)
    print(ans[ord(c) - 97][m] if ans[ord(c) - 97][m] != -1 else n)


import string
import bisect
import sys

def main():
  lines = sys.stdin.readlines()
  n = int(lines[0])
  s = lines[1]

  vals = {}
  for c in string.ascii_lowercase:
    a = [i for i, ch in enumerate(s) if ch == c]
    m = len(a)
    b = [0]
    for length in range(1, m + 1):
      best = n
      for i in range(m - length + 1):
        j = i + length - 1
        best = min(best, (a[j] - j) - (a[i] - i))
      b.append(best)
    vals[c] = b
  q = int(lines[2])
  r = []
  idx = 3
  while q > 0:
    q -= 1
    query = lines[idx].split()
    idx += 1
    m = int(query[0])
    c = query[1]
    i = bisect.bisect_right(vals[c], m)
    r.append(str(min(n, i + m - 1)))
  print('\n'.join(r))

main()

import sys
from math import log2,floor,ceil,sqrt
# import bisect
# from collections import deque

Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()
 
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return list(map(int, input().split()))
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
INF = 10 ** 18
MOD = 10**9+7

n = int(ri())
st = ri()
st = [ord(st[i])-ord('a') for i in range(len(st))]

dp = list2d(26,n+1,0)
for i in range(0,26):
    for j in range(n):
        cnt=  0
        for k in range(j,n):
            if st[k] != i:
                cnt+=1
            dp[i][cnt] = max(k-j+1,dp[i][cnt])

for i in range(26):
    for j in range(1,n+1):
        dp[i][j] = max(dp[i][j-1],dp[i][j])

# print(dp)

qq = int(ri())
for i in range(qq):
    temp= ri().split()
    ch = ord(temp[1])-ord('a')
    # print(dp[ch])
    m = int(temp[0])
    if m > n:
        m = n
    # print(ch,m)
    print(dp[ch][m])


n = int(input())
s = input()
dp = [[-1]*(n+1) for x in range(26)]

for c in range(26):
    for l in range(n):
        n_c = 0 
        for r in range(l, n):
            if s[r] == chr(ord('a') + c):
                n_c += 1
            dp[c][r-l+1-n_c] = max(dp[c][r-l+1-n_c], r-l+1)

all_res = []
for i in range(int(input())):
    m, c = input().split()
    m = int(m)
    idx = ord(c) - ord('a')
    all_res.append(dp[idx][m] if dp[idx][m] != -1 else n)

print('\n'.join(map(str, all_res)))


import sys
input = sys.stdin.readline
N = int(input())
S = list(map(lambda x: ord(x) - ord("a"), list(input())[: -1]))
res = [[0] * (N + 1) for _ in range(26)]
for c in range(26):
  for l in range(N):
    x = 0
    for r in range(l + 1, N + 1):
      x += S[r - 1] != c
      res[c][x] = max(res[c][x], r - l)
  for i in range(N): res[c][i + 1] = max(res[c][i + 1], res[c][i])
for _ in range(int(input())):
  x, s = input().split()
  x = int(x)
  s = ord(s) - ord("a")
  print(res[s][x])

import sys
input = sys.stdin.readline

n = int(input())
s = input()[:-1]
ans = [[-1]*(n+1) for _ in range(26)]

for c in range(26):
    for i in range(n):
        cnt = 0
        
        for j in range(i, n):
            if ord(s[j])-ord('a')!=c:
                cnt += 1
                
            ans[c][cnt] = max(ans[c][cnt], j-i+1)
            
for c in range(26):
    for i in range(1, n+1):
        ans[c][i] = max(ans[c][i], ans[c][i-1])

for _ in range(int(input())):
    m, c = input().split()
    print(ans[ord(c)-ord('a')][int(m)])

import sys
ii = lambda: sys.stdin.readline().strip()
idata = lambda: [int(x) for x in ii().split()]

# Ввод данных
n = int(ii())
s = ii()

# Будем считать, что "сет" - подотрезок, состоящий из одинаковых букв
# Далее создание словаря и внесение в него данных:
slov = {}
# В данном словаре на каждую букву есть два списка, в первом находятся
#   числа, которые сообщают нам размеры "сетов", а второй
#       список - расстояния между "сетами" (первый и
#           последний элементы этого списка - расстояние между началом всей строки и первым
#               "сетом" и расстояние между концом всей строки и последним "сетом")
for i in range(97, 97 + 26):
    slov[chr(i)] = [[], [1]]
slov[s[0]] = [[1], [0, 0]]  # Первый элемент обозначим вне цикла, чтобы позже не маяться с неточностями

for j in range(1, n):
    if slov[s[j]][1][-1] == 0:  # То есть, если нет расстояния между данной буквой и предыдущим "сетом"
        slov[s[j]][0][-1] += 1
    else:  # Добавление нового "сета"
        slov[s[j]][0] += [1]
        slov[s[j]][1] += [0]

    # Следующий for - увеличение расстояний между "сетами" для всех остальных букв
    for i in range(97, 97 + 26):
        if chr(i) != s[j]:
            slov[chr(i)][1][-1] += 1

# Пошла жара. Здесь обработка планов Надеко
for t in range(int(ii())):
    m, c = ii().split()
    m = int(m)
    a, b = slov[c]
    if sum(b) <= m:
        print(n)
    else:
        if not bool(a):  # Если нет "сетов" с данной буквой
            print(m)
        elif len(a) == 1:  # Если такой "сет" всего один
            print(a[0] + m)
        else:
            l, r = 0, 0
            ans = 0  # Максимальный ответ
            summ_a, summ_b = 0, 0
            used = 0  # Количество букв, которые мы заменили
            b1 = b[::]
            b1[0], b1[-1] = 0, 0
            count = 0  # Количество "сетов", которые мы используем на данный момент
            while r != len(a):
                if summ_b + b1[r] <= m:
                    summ_b += b1[r]
                    summ_a += a[r]
                    r += 1
                    ans = max(ans, m + summ_a)
                else:
                    summ_a -= a[l]
                    l += 1
                    summ_b -= b1[l]
            print(ans)

import sys
n=int(input())
s=input()
pfs=[[0 for _ in range(n+1)]for _ in range(26)]
for i in range(n):
  ch=ord(s[i])-ord('a')
  for  j in range(26):
    if j==ch:pfs[j][i+1]=pfs[j][i]+1
    else:pfs[j][i+1]=pfs[j][i]
#print(pfs)
dp=[[0 for _ in range(n+1)]for _ in range(26)]
for  c in range(26):
  for  l in range(n+1):
    for  r in range(l,n+1):
      tc=r-l-(pfs[c][r]-pfs[c][l])
      dp[c][tc]=max(dp[c][tc],r-l)
  for i  in range(1,n+1):
    dp[c][i]=max(dp[c][i],dp[c][i-1])

#print(dp)
A=[]
for q in range(int(input())):
  m,c=sys.stdin.readline().split()
  m=int(m)
  c=ord(c)-ord('a')
  ans=dp[c][m]
  print(ans)


import sys
n=int(input())
s=input()
pfs=[[0 for _ in range(n+1)]for _ in range(26)]
for i in range(n):
  ch=ord(s[i])-ord('a')
  for  j in range(26):
    if j==ch:pfs[j][i+1]=pfs[j][i]+1
    else:pfs[j][i+1]=pfs[j][i]
#print(pfs)
dp=[[0 for _ in range(n+1)]for _ in range(26)]
for  c in range(26):
  for  l in range(n+1):
    for  r in range(l,n+1):
      tc=r-l-(pfs[c][r]-pfs[c][l])
      dp[c][tc]=max(dp[c][tc],r-l)
  for i  in range(1,n+1):
    dp[c][i]=max(dp[c][i],dp[c][i-1])

#print(dp)
A=[]
for q in range(int(input())):
  m,c=sys.stdin.readline().split()
  m=int(m)
  c=ord(c)-ord('a')
  ans=dp[c][m]
  A.append(ans)
for i in A:
  print(i)