CSES - KILO 2017 4/5 - Coprime Queries
  • Time limit: 3.00 s
  • Memory limit: 512 MB

You are given a sequence a1,a2,,ana_1, a_2, \ldots, a_n consisting of positive integers. You have to answer qq queries. A query is defined by a triplet of numbers (l,r,x)(l, r, x). For each query, you have to find the largest pp such that lprl \le p \le r and apa_p is coprime with xx, or determine that there is no such pp.

Two numbers are coprime if the only positive integer that divides both of them is 1.

Input

The first line of the input contains two integers nn and qq.

The second line contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n.

The next qq lines contain queries. The ii-th of these lines contains three integers lil_i, rir_i and xix_i.

Output

For each query, output the largest such pp if it exists. Otherwise output -1.

Constraints

  • 1n,q1051 \le n, q \le 10^5
  • 1ai1051 \le a_i \le 10^5
  • 1lirin1 \le l_i \le r_i \le n
  • 1x1051 \le x \le 10^5

Example

Input:

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

Output:

3
1
-1
4