#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
using namespace std;

//@OtÆ[³
vector<int> graph[100000];
int parent[18][100000];
int depth[100000];


// Heavy-Light Decomposition p
vector< vector<int> > pre; // Op

vector< vector< vector<int> > > seg; // ÀÛÉBITÉg¤f[^ªüÁÄ¢é
int height[100000]; // height[i] = ¸_iªÜÜêéñÅÌiÌÊuB[³ªå«¢ÙÇheight[i]àå«¢B
int belong[100000]; // beling[i] = ¸_iª®·éñÌCfbNX
int next[100000];   // next[ñÌÔ] = ñ\zµÄéÆ«ÉÕËµ½¸_iªüé

// ÓÂ¤
int N,Q;
int value[100000];

// Heavy-Light Decomposition µÄ¢éÖ
int genLH(int pos,int num){
	if(pos == -1 || belong[pos] != -1){
		next[num] = pos;
		return 0;
	}else{
		height[pos] = genLH(parent[0][pos],num) + 1;
		belong[pos] = num;
		pre[num].push_back(value[pos]);
		return height[pos];
	}
}

void genTree(int pos,int prev,int dep){
	parent[0][pos] = prev;
	depth[pos] = dep;
	for(int i = 0 ; i < graph[pos].size() ; i++){
		if(graph[pos][i] != prev) genTree(graph[pos][i],pos,dep+1);
	}
}

// _uOðp¢Ä é¸_jð2^iñÁ½Æ«Ìeðparent[i][j]Éi[µÄ¨­B
void genLCA(){
	for(int i = 1 ; i < 18 ; i++){
		for(int j = 0 ; j < N ; j++){
			if(parent[i-1][j] != -1) parent[i][j] = parent[i-1][parent[i-1][j]];
		}
	}
}

// genLCA()ÅìÁ½îñð³Élog(N)ÅLCAßéBa{QÆB[³ðµ¦Ä©ç»êÅà¸_êvµÄÈ©Á½çÙ°ÁÆ·éB 
int getLCA(int x,int y){
	if(depth[x] < depth[y]) swap(x,y);
	int d = depth[x] - depth[y];
	for(int i = 0 ; i < 18 ; i++)
		if(d>>i&1) x = parent[i][x];
	if(x==y) return x;
	for(int i = 17 ; i >= 0 ; i--){
		if(parent[i][x] != parent[i][y]){
			x = parent[i][x];
			y = parent[i][y];
		}
	}	
	return parent[0][x];
}


// BIT p
void add(vector< vector<int> > &seg,int x,int v){
	while(x < seg.size()){
		seg[x].push_back(v);
		x += x & -x;
	}
}

int get(vector< vector<int> > &seg,int x,int k){
	int ans = 0;
	while(x){
		ans += lower_bound(seg[x].begin(),seg[x].end(),k) - seg[x].begin() - 1;
		x -= x & -x;
	}
	return ans;
}

// Heavy-Light Decompositionµ½âÂðgÁ½NGB
// ¸_from,toª¯¶ñÉ®µÄ¢éÈç»ÌñÅÌ[height[to],hegith[from]]ÉÜÜêékÈºÌðvZµA
// àµá¤ÈçAfromÌ®·éñÅ[1,height[from]]ÉÜÜêékÈºÌðvZµAÕËµ½ñÉoÁÄ¢­B
int query(int from,int to,int k){
	int A = belong[from] , B = belong[to];
	if(A==B){
		return get(seg[A],height[from],k) - get(seg[A],height[to]-1,k);
	}else{
		return get(seg[A],height[from],k) + query(next[A],to,k);
	}
}

int uniq[100000] , U = 0;
int idx[100000];

int cmp(const int &a,const int &b){
	return depth[a] > depth[b];
}

int main(){
	memset(belong,-1,sizeof(belong));
	memset(parent,-1,sizeof(parent));
	memset(height,-1,sizeof(height));
	scanf("%d%d",&N,&Q);
	for(int i = 0 ; i < N ; i++){
		scanf("%d",&value[i]);
		uniq[U++] = value[i];
	}
	for(int i = 0 ; i < N - 1 ; i++){
		int a,b;
		scanf("%d%d",&a,&b);
		--a,--b;
		graph[a].push_back(b);
		graph[b].push_back(a);
	}
	sort(uniq,uniq+U);
	genTree(0,-1,0);
	for(int i = 0 ; i < N ; i++) idx[i] = i;
	sort(idx,idx+N,cmp);
	for(int i = 0 ; i < N ; i++){
		if(belong[idx[i]] == -1){
			pre.push_back(vector<int>(1,-1));
			genLH(idx[i],pre.size()-1);
		}
	}
	for(int i = 0 ; i < pre.size() ; i++){
		seg.push_back( vector< vector<int> > (pre[i].size(),vector<int>(1,-1)) );
		for(int j = 1 ; j < pre[i].size() ; j++) add(seg.back(),j,pre[i][j]);
		for(int j = 0 ; j < seg.back().size() ; j++) sort(seg.back()[j].begin(),seg.back()[j].end());
	}
	genLCA();
	for(int i = 0 ; i < Q ; i++){
		int a,b,c;
		scanf("%d%d%d",&a,&b,&c);
		--a,--b;
		int l = 0 , r = U-1;
		int p = getLCA(a,b);
		while(l!=r){
			int m = (l+r+1)/2;
			int g = query(a,p,uniq[m]) + query(b,p,uniq[m]) - (value[p] < uniq[m]);
			
			if(g < c) l = m;
			else r = m-1;
		}
		printf("%d\n",uniq[l]);
	}
}

Measured memory_bytes: 0