Text Processor

Count the distinct substrings inside each fixed-width window of a lowercase string for many queries.

Hard8String matchingSliding windowSegment treeNo attempts yetTime limit1sMemory limit256 MB

Problem

Inês is new to programming. She is writing a simple document editor, and so far it can only add text to a blank document. Her little sister Rita is fascinated by the symbols on the screen and wants to play with the app, so Inês cannot get any work done. To keep working, Inês turns the situation into a game for Rita.

Rita writes whatever she likes in the document. Inês then picks a stretch of the document of width WW and asks Rita how many distinct sequences of symbols that stretch contains. Rita jumps at the game, but there is a problem. Inês cannot write a program that answers her own questions yet.

You are given the text Rita wrote and the questions Inês asks. For each question, count the distinct substrings inside that range. A substring is a run of consecutive letters of the document, and the empty string is not counted.

Input

The first line contains the text DD that Rita wrote. The text is made of the lowercase letters aa to zz only. The second line contains two integers QQ and WW separated by a space, where QQ is the number of questions and WW is the fixed width Inês picks. Each of the next QQ lines contains one integer ii describing a question about the range [i,i+W1][i, i+W-1].

Output

Print the answer to each question on its own line, in the order the questions are given.

Constraints

  • 1D1000001 \le |D| \le 100\,000, where D|D| is the length of the text
  • 1Q1000001 \le Q \le 100\,000
  • 1WD1 \le W \le |D|
  • 1iDW+11 \le i \le |D| - W + 1, and positions are counted from 1