#include <bits/stdc++.h>
using namespace std;

class Tree{
public:
	//[0,n)
	int n,logn,root;
	vector< vector<int> > child;
	vector<vector<int> > parent;
	vector<int> depth;
	Tree(int n_,vector<pair<int,int>> es,int root) : root(root){
		n = n_;
		logn = 0;
		while(n_){
			++logn;
			n_ /= 2;
		}
		parent.resize(logn,vector<int>(n,-1));
		depth.resize(n,-1);
		child.resize(n);
		vector<vector<int>> g(n);
		for( auto e : es ){
			g[e.first].push_back(e.second);
			g[e.second].push_back(e.first);
		}
		dfs(g);
		gen_lca();
		verify();
	}
	bool verify(){
		for(int i = 0 ; i < n ; i++)
			assert( depth[i] != -1 );
	}

	int lca(int x,int y){
		if( depth[x] < depth[y] )swap(x,y);
		int d = depth[x] - depth[y];
		for(int i = 0 ; i < logn ; i++)
			if( d >> i & 1 ) x = parent[i][x];
		if( x == y ) return x;
		
		for(int i = logn-1 ; i >= 0 ; i--){
			if( parent[i][x] != parent[i][y] ){
				x = parent[i][x];
				y = parent[i][y];
			}
		}
		return parent[0][x];
	}
private:
	int gen_lca(){
		for(int i = 1 ; i < logn ; i++){
			for(int j = 0 ; j < n ; j++)
				if( parent[i-1][j] != -1 ) 
					parent[i][j] = parent[i-1][parent[i-1][j]];
		}
	}
	int dfs(const vector<vector<int>> &g){
		stack< array<int,3> > S;
		S.push(array<int,3>{root,-1,0});
		while( S.size() ){
			int x = S.top()[0];
			int p = S.top()[1];
			int d = S.top()[2];
			S.pop();
			parent[0][x] = p;
			depth[x] = d;
			for( auto e : g[x] ){
				if( e != p ){
					S.push(array<int,3>{e,x,d+1});
					child[x].push_back(e);
				}
			}
		}
	}
};


struct BIT{
	vector< vector<int> > seg;
	// [1,n]
	BIT(int N){
		seg.resize(N+1);
	};
	int get_(int i,int x){
		int ans = 0;
		for(;i;i-=i&-i){
			ans += upper_bound(seg[i].begin(),seg[i].end(),x) - seg[i].begin();
		}
		return ans;
	}
	void add(int i,int x){
		for(;i<seg.size();i+=i&-i){
			seg[i].push_back(x);
		}
	}
	int get(int l,int r,int x){
		return get_(r,x) - get_(l-1,x);
	}
};
template<class SegmentTree> class HeavyLightDecomp{
public:
	Tree tr;
	vector< pair<int,int> > where; // (id,pos)
	vector< vector<int> > pathSeq;
	vector<SegmentTree> seg;
	HeavyLightDecomp(const Tree &tr) : tr(tr){
		// init
		where.resize(tr.n,{-1,-1});
		vector<int> subtree(tr.n);
		vector<pair<int,int>> sortedIdx;
		for(int i = 0 ; i < tr.n ; i++)
			sortedIdx.push_back({tr.depth[i],i});
		sort(sortedIdx.begin(),sortedIdx.end());
		
		// calc sizes of each subtree
		for(int I = tr.n-1 ; I >= 0 ; I--){
			int i = sortedIdx[I].second;
			subtree[i] = 1;
			for( auto e : tr.child[i] ) subtree[i] += subtree[e];
		}
		// do heavyLightDecomp Part1
		for(int I = 0 ; I < tr.n ; I++){
			int i = sortedIdx[I].second;
			if( where[i].first == -1 ){
				where[i].first = pathSeq.size();
				pathSeq.push_back(vector<int>());
			}
			where[i].second = pathSeq[where[i].first].size();
			pathSeq[where[i].first].push_back(i);
			for( auto e : tr.child[i] ){
				if( 2*subtree[e] > subtree[i] ){
					where[e].first = where[i].first;
				}
			}
		}
		// Set segtrees to each heavy-path.
		for(int i = 0 ; i < pathSeq.size() ; i++){
			int n_ = 1;
			while( n_ < pathSeq[i].size() ) n_ *= 2;
			seg.push_back(SegmentTree(n_));
		}
	}
	
	int get(int a,int b,int v){
		int p = tr.lca(a,b);
		return get(a,p,v,0) + get(b,p,v,0) - get(p,p,v,0); //????¨????
	}
	private: 
	inline int get(int c,int p,int v,int isEdgeQuery){
		int id1 = where[c].first;
		int id2 = where[p].first;
		int l = where[p].second + 1;
		int r = where[c].second + 1;
		
		int ans = 0;
		if( id1 == id2 ){
			ans += seg[id1].get(l+isEdgeQuery,r,v); //????¨????
		}else{
			ans += seg[id1].get(1,r,v); //????¨????
			ans += get(tr.parent[0][pathSeq[id1][0]],p,v,isEdgeQuery);
		}
		return ans;
	}
};
 
int in(){
	int n;
	scanf("%d",&n);
	return n;
}

int arr[100010];
int main(){
	int N = in();
	int Q = in();
	vector< pair<int,int> > es;
	for(int i = 0 ; i < N ; i++)
		arr[i] = in();
	
	for(int i = 0 ; i < N-1 ; i++){
		int a = in();
		int b = in();
		--a,--b;
		es.push_back({a,b});
	}
	Tree tr(N,es,0);
	HeavyLightDecomp<BIT> hl(tr);
	for(int i = 0 ; i < N ; i++){
		hl.seg[hl.where[i].first].add(hl.where[i].second+1,arr[i]);
	}
	for( auto &s : hl.seg ){
		for(int j = 0 ; j < s.seg.size() ; j++)
			sort(s.seg[j].begin(),s.seg[j].end());
	}
	sort(arr,arr+N);
	for(int i = 0 ; i < Q ; i++){
		int a = in();
		int b = in();
		int k = in();
		--a,--b;
		int l = 0, r = N-1;
		while( l != r ){
			int m = (l+r)/2;
			if( hl.get(a,b,arr[m]) >= k ){
				r = m;
			}else{
				l = m+1;
			}
		}
		printf("%d\n",arr[l]);
	}
	
	
	
	
} 

Measured memory_bytes: 41060