Ssari and Bird's Pyramid

No attempts yetTime limit1sMemory limit256 MB

Problem

Ssari and Bird had nothing at all to do, so they built a pyramid of height NN in the back yard and decided to write their favorite word on it. Row ii from the top has ii cells.

The word goes in one letter per cell, in a zigzag. Row 1 fills from left to right, row 2 from right to left, row 3 from left to right again, and so on. Once the word is written out, it starts over from its first letter.

For N=6N = 6 and the word JANJETINA the pyramid comes out like this.

     J
    N A
   J E T
  J A N I
 A N J E T
N A J A N I

Bird picks a row number aia_i and an uppercase letter cic_i, then asks "how many times does cic_i appear in row aia_i?". Answer Bird's KK questions and help Ssari out.

Input

The first line contains the height of the pyramid, NN (1N10181 \le N \le 10^{18}).

The second line contains a word made only of uppercase letters. The word is at most 10610^6 letters long.

The third line contains the number of rows Bird picked, KK (1K500001 \le K \le 50000).

Each of the next KK lines contains aia_i and cic_i separated by a space (1aiN1 \le a_i \le N, and cic_i is an uppercase letter).

Output

Print KK lines. Line ii holds the number of times cic_i appears in row aia_i of the pyramid.