#include <bits/stdc++.h>
#define int long long
using namespace std;
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
typedef long long ll;
template <typename T>
struct sparse_table{
static const int N = 1e5 + 10, L = 20;
T a[N];
int d[N][L], rem[N];
void build(int n) {
for (int i = 1; i <= n; i++) { d[i][0] = i; }
for (int j = 1; j <= L - 1; j++) {
for (int i = 1; i <= n; i++) {
if (i + (1 << j) - 1 > n) { continue; }
d[i][j] = gcd(a[d[i][j - 1]], a[d[i + (1 << (j - 1))][j - 1]]);
}
}
for (int i = 1; i <= n; i++) { rem[i] = log2(i); }
}
T get(int l, int r) {
int lg = rem[r - l + 1];
return gcd(a[d[l][lg]], a[d[r - (1 << lg) + 1][lg]]);
}
};
sparse_table<ll> table;
const int N = 1e5 + 10;
ll a[N];
vector<pair<int, ll>> rig[N];
void precalc(int n) {
for (int i = 1; i <= n; i++) {
table.a[i] = a[i];
}
table.build(n);
rig[n] = {{n, a[n]}};
for (int l = n - 1; l >= 1; l--) {
rig[l] = {{l, a[l]}};
for (auto [r, val] : rig[l + 1]) {
val = __gcd(val, a[l]);
if (val == rig[l].back().second) {
rig[l].back().first = r;
} else {
rig[l].emplace_back(r, val);
}
}
}
}
vector<ll> get(int l, int r, int k) {
if (k >= r - l + 1) {
return {0};
} else if (k == 0) {
return {table.get(l, r)};
} else {
vector<ll> res;
{
auto nxt = get(l + 1, r, k - 1);
for (ll x : nxt) {
res.push_back(x);
}
}
{
auto nxt = get(l, r - 1, k - 1);
for (ll x : nxt) {
res.push_back(x);
}
}
for (auto [x, val] : rig[l]) {
auto nxt = get(x + 2, r, k - 1);
for (auto nxt_val : nxt) {
res.push_back(gcd(val, nxt_val));
}
}
return res;
}
}
ll solve(int l, int r, int k) {
auto res = get(l, r, k);
ll ans = 0;
for (ll x : res) {
ans = max(ans, x);
}
return ans;
}
signed
main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
#endif
int n, q;
cin >> n >> q;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
precalc(n);
while (q--) {
int l, r, k;
cin >> l >> r >> k;
cout << solve(l, r, k) << "\n";
}
#ifdef LOCAL
cout << "\nTime elapsed: " << double(clock()) / CLOCKS_PER_SEC << " s.\n";
#endif
}