Perhaps Strings Are Inevitable

Limits 1s, 1.0 GB

Strings are inevitable in life. They give meaning to our expressions. Strings come in life in many ways, like a well-written letter for hearts, a nice song composed to heal the souls. For NGPC contestants like you, strings come in the form of a programming problem to give joy.

You will be given a list L\textbf{L} of N\textbf{N} strings and M\textbf{M} queries. The queries are of two types. They are described below:

A prefix of a string TT is a substring of TT that occurs at the beginning of TT.

Input

The first line of the input file will contain a single positive integer N\textbf{N} (1N105)(1 \leq N \leq 10^{5}) which denotes the number of strings in the list L\textbf{L}. Each of the next NN lines will contain a string Li\textbf{L}_{i} (1Li105)(1 \leq |L_{i}| \leq 10^{5}). After that, there will be a single positive integer M\textbf{M} (1M105)(1 \leq M \leq 10^{5}). Each of the next MM lines will contain each of the two types of queries described below:

It is guaranteed that all the strings in the input file contains lowercase English alphabets (az)(‘a’ - ‘z’) only and there will be at least one query of type 2.

Other constraints:
1i=1NLi3×1061\leq \sum_{i=1}^{N} |L_{i}|\leq 3 \times 10^{6}

1Pi+Si3×1061\leq \sum |P_{i}| + \sum|S_{i}|\leq 3 \times 10^{6}

Output

For each of the 2nd2^{nd} type of query, print the number of strings which have a prefix that matches with given prefix SS.

Sample

InputOutput
2
abcdx
abcex
3
1 abce d
2 abce
2 abcd
0
2