#include //using namespace std; #pragma GCC target("avx") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #define rep(i,j,n) for(ll i=(ll)(j);i<(ll)(n);i++) #define REP(i,j,n) for(ll i=(ll)(j);i<=(ll)(n);i++) #define per(i,j,n) for(ll i=(ll)(j);(ll)(n)<=i;i--) #define ll long long #define ALL(a) (a).begin(),(a).end() #define pb emplace_back #define mp std::make_pair // #define endl "\n" //using std::endl; using std::cin; using std::cout; using std::vector; using std::string; using std::upper_bound; using std::lower_bound; using vi=vector; using vii=vector; using pii=std::pair; int main(){ std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int N; cin>>N; vector X(N); rep(i,0,N) cin>>X[i]; vector> data(N); rep(i,0,N) data[i]=mp(X[i],i); sort(ALL(X)); int Q; cin>>Q; while(Q--){ int l,r,x; cin>>l>>r>>x; l--,r--; int ans=1e9; int ind=lower_bound(ALL(data),mp(x,0))-data.begin(); rep(i,ind,N){ if(l<=data[i].second&&data[i].second<=r){ ans=std::min(ans,data[i].first-x); break; } } per(i,ind-1,0){ if(l<=data[i].second&&data[i].second<=r){ ans=std::min(ans,x-data[i].first); break; } } cout<