#include <bits/stdc++.h>
using namespace std;
const int maxn = 333333, maxm = 1111111, mod = 998244353;
template <typename T>
inline void read(T &x) {
  x = 0;
  bool f = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') f |= ch == '-', ch = getchar();
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  if (f) x = -x;
}
int n, m, q, a[maxn], pr[maxn], pl, mn[maxm], fa[maxn], id[maxn], at[maxm];
bool vis[maxm];
map<pair<int, int>, bool> mp;
inline int getfa(int x) { return x == fa[x] ? x : fa[x] = getfa(fa[x]); }
inline void unite(int x, int y) {
  x = getfa(x);
  y = getfa(y);
  if (x != y) fa[x] = y;
}
inline bool check(int x, int y) {
  x = getfa(x);
  y = getfa(y);
  return x == y;
}
int main() {
  read(n);
  read(q);
  for (int i = (1); i <= (n); i++) read(a[i]), m = max(m, a[i] + 1);
  for (int i = (2); i <= (m); i++) {
    if (!vis[i]) pr[++pl] = i, at[i] = pl + n, mn[i] = i;
    for (int j = (1); j <= (pl); j++) {
      if (i * pr[j] > m) break;
      vis[i * pr[j]] = true;
      mn[i * pr[j]] = pr[j];
      if (i % pr[j] == 0) break;
    }
  }
  for (int i = (1); i <= (n + pl); i++) fa[i] = i;
  for (int i = (1); i <= (n); i++) {
    int x = a[i];
    while (x != 1) unite(i, at[mn[x]]), x /= mn[x];
  }
  for (int i = (1); i <= (n + pl); i++) id[i] = getfa(i);
  for (int i = (1); i <= (n); i++) {
    int x = a[i], tmp[111], tl = 0;
    while (x != 1) tmp[++tl] = id[at[mn[x]]], x /= mn[x];
    x = a[i] + 1;
    while (x != 1) tmp[++tl] = id[at[mn[x]]], x /= mn[x];
    sort(tmp + 1, tmp + tl + 1);
    tl = unique(tmp + 1, tmp + tl + 1) - tmp - 1;
    for (int j = (1); j <= (tl); j++)
      for (int k = (1); k <= (tl); k++) mp[make_pair(tmp[j], tmp[k])] = true;
  }
  while (q--) {
    int s, t;
    read(s);
    read(t);
    s = id[s];
    t = id[t];
    if (s == t)
      puts("0");
    else if (mp[make_pair(s, t)])
      puts("1");
    else
      puts("2");
  }
}

### Prompt

Create a solution in CPP for the following problem:

Consider a sequence of distinct integers a_1, …, a_n, each representing one node of a graph. There is an edge between two nodes if the two values are not coprime, i. e. they have a common divisor greater than 1.

There are q queries, in each query, you want to get from one given node a_s to another a_t. In order to achieve that, you can choose an existing value a_i and create new value a_{n+1} = a_i ⋅ (1 + a_i), with edges to all values that are not coprime with a_{n+1}. Also, n gets increased by 1. You can repeat that operation multiple times, possibly making the sequence much longer and getting huge or repeated values. What's the minimum possible number of newly created nodes so that a_t is reachable from a_s?

Queries are independent. In each query, you start with the initial sequence a given in the input.

Input

The first line contains two integers n and q (2 ≤ n ≤ 150 000, 1 ≤ q ≤ 300 000) — the size of the sequence and the number of queries.

The second line contains n distinct integers a_1, a_2, …, a_n (2 ≤ a_i ≤ 10^6, a_i ≠ a_j if i ≠ j).

The j-th of the following q lines contains two distinct integers s_j and t_j (1 ≤ s_j, t_j ≤ n, s_j ≠ t_j) — indices of nodes for j-th query.

Output

Print q lines. The j-th line should contain one integer: the minimum number of new nodes you create in order to move from a_{s_j} to a_{t_j}.

Examples

Input


3 3
2 10 3
1 2
1 3
2 3


Output


0
1
1


Input


5 12
3 8 7 6 25
1 2
1 3
1 4
1 5
2 1
2 3
2 4
2 5
3 1
3 2
3 4
3 5


Output


0
1
0
1
0
1
0
1
1
1
1
2

Note

In the first example, you can first create new value 2 ⋅ 3 = 6 or 10 ⋅ 11 = 110 or 3 ⋅ 4 = 12. None of that is needed in the first query because you can already get from a_1 = 2 to a_2 = 10.

In the second query, it's optimal to first create 6 or 12. For example, creating 6 makes it possible to get from a_1 = 2 to a_3 = 3 with a path (2, 6, 3).

<image>

In the last query of the second example, we want to get from a_3 = 7 to a_5 = 25. One way to achieve that is to first create 6 ⋅ 7 = 42 and then create 25 ⋅ 26 = 650. The final graph has seven nodes and it contains a path from a_3 = 7 to a_5 = 25.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 333333, maxm = 1111111, mod = 998244353;
template <typename T>
inline void read(T &x) {
  x = 0;
  bool f = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') f |= ch == '-', ch = getchar();
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  if (f) x = -x;
}
int n, m, q, a[maxn], pr[maxn], pl, mn[maxm], fa[maxn], id[maxn], at[maxm];
bool vis[maxm];
map<pair<int, int>, bool> mp;
inline int getfa(int x) { return x == fa[x] ? x : fa[x] = getfa(fa[x]); }
inline void unite(int x, int y) {
  x = getfa(x);
  y = getfa(y);
  if (x != y) fa[x] = y;
}
inline bool check(int x, int y) {
  x = getfa(x);
  y = getfa(y);
  return x == y;
}
int main() {
  read(n);
  read(q);
  for (int i = (1); i <= (n); i++) read(a[i]), m = max(m, a[i] + 1);
  for (int i = (2); i <= (m); i++) {
    if (!vis[i]) pr[++pl] = i, at[i] = pl + n, mn[i] = i;
    for (int j = (1); j <= (pl); j++) {
      if (i * pr[j] > m) break;
      vis[i * pr[j]] = true;
      mn[i * pr[j]] = pr[j];
      if (i % pr[j] == 0) break;
    }
  }
  for (int i = (1); i <= (n + pl); i++) fa[i] = i;
  for (int i = (1); i <= (n); i++) {
    int x = a[i];
    while (x != 1) unite(i, at[mn[x]]), x /= mn[x];
  }
  for (int i = (1); i <= (n + pl); i++) id[i] = getfa(i);
  for (int i = (1); i <= (n); i++) {
    int x = a[i], tmp[111], tl = 0;
    while (x != 1) tmp[++tl] = id[at[mn[x]]], x /= mn[x];
    x = a[i] + 1;
    while (x != 1) tmp[++tl] = id[at[mn[x]]], x /= mn[x];
    sort(tmp + 1, tmp + tl + 1);
    tl = unique(tmp + 1, tmp + tl + 1) - tmp - 1;
    for (int j = (1); j <= (tl); j++)
      for (int k = (1); k <= (tl); k++) mp[make_pair(tmp[j], tmp[k])] = true;
  }
  while (q--) {
    int s, t;
    read(s);
    read(t);
    s = id[s];
    t = id[t];
    if (s == t)
      puts("0");
    else if (mp[make_pair(s, t)])
      puts("1");
    else
      puts("2");
  }
}

```