474_F. Ant colony
Mole is hungry again. He found one ant colony, consisting of n ants, ordered in a row. Each ant i (1 ≤ i ≤ n) has a strength si.

In order to make his dinner more interesting, Mole organizes a version of «Hunger Games» for the ants. He chooses two numbers l and r (1 ≤ l ≤ r ≤ n) and each pair of ants with indices between l and r (inclusively) will fight. When two ants i and j fight, ant i gets one battle point only if si divides sj (also, ant j gets one battle point only if sj divides si). 

After all fights have been finished, Mole makes the ranking. An ant i, with vi battle points obtained, is going to be freed only if vi = r - l, or in other words only if it took a point in every fight it participated. After that, Mole eats the rest of the ants. Note that there can be many ants freed or even none.

In order to choose the best sequence, Mole gives you t segments [li, ri] and asks for each of them how many ants is he going to eat if those ants fight.

Input

The first line contains one integer n (1 ≤ n ≤ 105), the size of the ant colony. 

The second line contains n integers s1, s2, ..., sn (1 ≤ si ≤ 109), the strengths of the ants. 

The third line contains one integer t (1 ≤ t ≤ 105), the number of test cases. 

Each of the next t lines contains two integers li and ri (1 ≤ li ≤ ri ≤ n), describing one query.

Output

Print to the standard output t lines. The i-th line contains number of ants that Mole eats from the segment [li, ri].

Examples

Input

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


Output

4
4
1
1

Note

In the first test battle points for each ant are v = [4, 0, 2, 0, 2], so ant number 1 is freed. Mole eats the ants 2, 3, 4, 5.

In the second test case battle points are v = [0, 2, 0, 2], so no ant is freed and all of them are eaten by Mole.

In the third test case battle points are v = [2, 0, 2], so ants number 3 and 5 are freed. Mole eats only the ant 4.

In the fourth test case battle points are v = [0, 1], so ant number 5 is freed. Mole eats the ant 4.
```python
from math import gcd

class SegTree:
    def __init__(self, arr = None, length = None):
        """
        Creates a segment tree. If arr (a list) is given, length is ignored,
        and we build a segment tree with underlying array arr. If no list is
        given, length (an int) must be given, and we build a segment tree with
        underlying all-zero array of that length.
        """
        if arr is not None:
            self.n = len(arr)
            self.t = [1 for _ in range(2*self.n)]
            self.ct = [0]*self.n + [1]*self.n
            self.construct(arr)
        else:
            assert False
            self.n = length
            self.t = [1 for _ in range(2*self.n)]

    def construct(self, arr):
        """
        Constructs the segment tree from given array (assumed to be of the
        right length).
        """
        self.t[self.n:] = arr
        for i in reversed(range(0, self.n)):
            self.t[i] = gcd(self.t[i*2], self.t[i*2+1])
            # print(i, self.t[i], self.t[i*2], self.t[i*2+1])
            if self.t[i] == self.t[i*2]:
                self.ct[i] += self.ct[i*2]
            if self.t[i] == self.t[i*2 + 1]:
                self.ct[i] += self.ct[i*2 + 1]

    def modify(self, p, val):
        """
        Sets the value at index p to val.
        """
        p += self.n
        self.t[p] = val
        self.ct[p] = 1
        while p > 1:
            self.t[p//2] = gcd(self.t[p], self.t[p ^ 1])
            self.ct[p//2] = 0
            if self.t[p//2] == self.t[p]:
                self.ct[p//2] += self.ct[p]
            if self.t[p//2] == self.t[p ^ 1]:
                self.ct[p//2] += self.ct[p ^ 1]
            p //= 2

    def gcd_query(self, l, r):
        l += self.n
        r += self.n
        res = self.t[l]
        while l < r:
            if l&1:
                res = gcd(res, self.t[l])
                l += 1
            if r&1:
                r -= 1
                res = gcd(res, self.t[r])
            l //= 2
            r //= 2
        return res

    def query_num_eq_gcd(self, l, r):
        """
        Gets the sum of all values in the range [l, r) in the underlying array.
        """
        my_gcd = self.gcd_query(l, r)
        l += self.n
        r += self.n
        res = 0
        while l < r:
            if l&1:
                if self.t[l] == my_gcd:
                    res += self.ct[l]
                l += 1
            if r&1:
                r -= 1
                if self.t[r] == my_gcd:
                    res += self.ct[r]
            l //= 2
            r //= 2
        return res

import sys
n = int(input())
s = [int(x) for x in input().split()]
st = SegTree(arr=s)
t = int(input())
for _ in range(t):
    l, r = [int(x) for x in sys.stdin.readline().split()]
    # print(f"gcd = {st.gcd_query(l-1, r)}")
    # print(f"num eq to gcd = {st.query_num_eq_gcd(l-1, r)}")
    print(r - l + 1 - st.query_num_eq_gcd(l-1, r))
    # print(st.t)
    # print(st.ct)
    # print()

```