You are given a string with length , and the size of the alphabet also is
.
There are queries. For a query, you are given two integers
and you need to answer the number of different strings (which can be empty) that can be obtained by removing a substring containing
.
The first line contains one integer
(
), denoting the length of the string
.
The second line contains
integers
(
).
The third line contains one integer
(
), denoting the number of queries.
For the
-th to
-th lines, each line contains two integers
(
), denoting a query.
For each query, output a number in a line indicating the answer.
The string in the sample is equal to 'abca'.For the first query
:
'bca' can be obtained by removing substring.
'ca' can be obtained by removing substring.
'a' can be obtained by removing substring.
Empty string can be obtained by removing substring.
So the answer is.
For the third query
:
'aa' can be obtained by removing substring.
'a' can be obtained by removing substringor
.
Empty string can be obtained by removing substring.
So the answer is
.