A palindromic string is a string that reads the same forward as it does backward.
Yuuka has a string s, and she would like to ask some questions about it. In each question, Yuuka will give you a list of integers x_1,x_2,…,x_k (where x_i is 1-indexed) and an integer l. Let t be the concatenation of s(x_1,l),s(x_2,l),…,s(x_k,l), where s(x,p) is a substring of s with length p that starts at position x. Yuuka would like to know the total number of palindromic substrings in t.
The input contains zero or more test cases, and is terminated by end-of-file. For each test case:
The first line contains an integer n denoting the length of the string (1≤n≤105).
The second line contains n integers s_1,s_2,…,s_n denoting the string s (1≤s_i≤n; the alphabet Yuuka uses may be large, so we just denote its characters by integers from 1 to n).
The third line contains an integer m denoting the number of questions (1≤m≤105).
The i-th of the following m lines contains two integers k_i and l_i, followed by k_i integers x_i,1,x_i,2,…,x_i,k_i (1≤k_i≤105, 1≤l_i≤n, k_i⋅l_i≤109, 1≤x_i,j≤n−l_i+1).
It is guaranteed that neither the sum of all n nor the sum of all k_i exceeds 105.
For each question, output an integer denoting the number of palindromic substrings.