Problem: We call an array b_1, b_2, …, b_m good, if there exist two indices i < j such that b_i ⋅ b_j is a [perfect square](https://en.wikipedia.org/wiki/Square_number).

Given an array b_1, b_2, …, b_m, in one action you can perform one of the following: 

  * multiply any element b_i by any prime p; 
  * divide any element b_i by prime p, if b_i is divisible by p. 



Let f(b_1, b_2, …, b_m) be the minimum number of actions needed to make the array b good.

You are given an array of n integers a_1, a_2, …, a_n and q queries of the form l_i, r_i. For each query output f(a_{l_i}, a_{l_i + 1}, …, a_{r_i}).

Input

The first line contains two integers n and q (2 ≤ n ≤ 194 598, 1 ≤ q ≤ 1 049 658) — the length of the array and the number of queries.

The second line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 5 032 107) — the elements of the array.

Each of the next q lines contains two integers l_i and r_i (1 ≤ l_i < r_i ≤ n) — the parameters of a query.

Output

Output q lines — the answers for each query in the order they are given in the input.

Example

Input

10 10
34 37 28 16 44 36 43 50 22 13
1 3
4 8
6 10
9 10
3 10
8 9
5 6
1 4
1 7
2 6


Output

2
0
1
3
0
1
1
1
0
0

Note

In the first query of the first sample you can multiply second number by 7 to get 259 and multiply the third one by 37 to get 1036. Then a_2 ⋅ a_3 = 268 324 = 518^2.

In the second query subarray is already good because a_4 ⋅ a_6 = 24^2.

In the third query you can divide 50 by 2 to get 25. Then a_6 ⋅ a_8 = 30^2.

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
using cat = long long;
struct query {
  int l, r, id;
  bool operator<(const query& Q) const { return r < Q.r; }
};
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(10);
  int N, Q, MX = 5050000;
  cin >> N >> Q;
  vector<int> div(MX + 1, 1);
  for (int i = 2; i <= MX; i++)
    if (div[i] == 1) {
      div[i] = i;
      for (int j = i; j <= MX / i; j++) div[i * j] = i;
    }
  vector<vector<int> > A(N);
  vector<vector<int> > prod_groups(MX);
  vector<int> prod_sz(MX, 0);
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    while (a > 1) {
      int e = 0, p = div[a];
      while (a % p == 0) a /= p, e++;
      if (e & 1) A[i].push_back(p);
    }
    int sz = A[i].size();
    for (int j = 0; j < (1 << sz); j++) {
      int prod = 1, n = 0;
      for (int k = 0; k < sz; k++)
        if ((j >> k) & 1) prod *= A[i][k], n++;
      prod_groups[prod].push_back(i);
      prod_sz[prod] = n;
    }
  }
  vector<vector<int> > last(N, vector<int>(15, -1));
  int opt[8];
  for (int i = 0; i < MX; i++)
    if (!prod_groups[i].empty()) {
      int sz = prod_groups[i].size();
      for (int j = 0; j < 8; j++) opt[j] = -1;
      for (int j = 0; j < sz; j++) {
        int cur = prod_groups[i][j];
        for (int k = 0; k < 8; k++)
          if (opt[k] != -1)
            last[cur][k + A[cur].size() - prod_sz[i]] =
                max(last[cur][k + A[cur].size() - prod_sz[i]], opt[k]);
        opt[A[cur].size() - prod_sz[i]] = cur;
      }
    }
  for (int i = 0; i < N; i++)
    for (int j = 0; j < 14; j++)
      last[i][j + 1] = max(last[i][j + 1], last[i][j]);
  vector<int> last_RMQ[15][18];
  for (int i = 0; i < 15; i++) {
    for (int k = 0; k < 18; k++) last_RMQ[i][k].resize(N + 1, -1);
    for (int j = 0; j < N; j++) last_RMQ[i][0][j] = last[j][i];
    for (int k = 1; k < 18; k++)
      for (int j = 0; j < N; j++)
        last_RMQ[i][k][j] = max(last_RMQ[i][k - 1][j],
                                last_RMQ[i][k - 1][min(N, j + (1 << (k - 1)))]);
  }
  for (int q = 0; q < Q; q++) {
    int l, r;
    cin >> l >> r;
    l--;
    int ans = 14;
    for (int k = 17; k >= 0; k--)
      if (l + (1 << k) <= r) {
        r -= (1 << k);
        for (int i = 0; i < ans; i++)
          if (last_RMQ[i][k][r] >= l) {
            ans = i;
            break;
          }
      }
    cout << ans << "\n";
  }
  return 0;
}