Given a sequence of N numbers a1, a2, ..., aN, and a number of d-queries. A d-query is a pair (i, j) (1 ≤ ijN). For each d-query (i, j), you have to return the number of distinct elements in the subsequence ai, ai + 1, ..., aj.

Input

Output

Sample Input 1

5
1 1 2 1 3
3
1 5
2 4
3 5

Sample Output 1

3
2
3

Sample Input 2

10
8 1 4 3 10 1 7 4 8 1
5
1 1
3 4
2 9
2 2
4 10

Sample Output 2

1
2
6
1
6