#include using namespace std; #define rep(i,n) for(int i = 0; i < (n); ++i) #define rrep(i,n) for(int i = (n)-1; i >= 0; --i) #define chmax(a, b) a = max(a, b) template void chmin(T& a, const T& b) { a = min(a, b); } #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() using ll = long long; using P = pair; using VI = vector; using VVI = vector; using VL = vector; using VVL = vector; struct Q { int i; int l, r, x; bool operator<(Q& y) { int bx = l / 550, by = y.l / 550; return (bx < by) || (bx == by && r < y.r); } }; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; VI x(n); rep(i, n) cin >> x[i]; int q; cin >> q; vector qs(q); rep(i, q) { qs[i].i = i; cin >> qs[i].l >> qs[i].r >> qs[i].x; qs[i].l--; } sort(all(qs)); int cur_b = -1, blast = -1; VI ans(q); set s; int p = -1; rep(i, q) { int l = qs[i].l, r = qs[i].r, z = qs[i].x; int b = l / 550; if (b != cur_b) { cur_b = b; s.clear(); blast = 550 * (b + 1); p = blast; } while(p < r) s.insert(x[p++]); auto it = s.lower_bound(z); int tans = 1001001001; if (it != s.end()) { chmin(tans, *it - z); } if (it != s.begin()) { it--; chmin(tans, z - *it); } for(int j = min({blast, n, r}) - 1; j >= l; --j) { chmin(tans, abs(x[j] - z)); } ans[qs[i].i] = tans; } rep(i, q) cout << ans[i] << '\n'; }