#include <set>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cassert>

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)

using namespace std;

inline int getInt(){ int s; scanf("%d", &s); return s; }

template<class T>
struct Node{
  Node *parent;
  Node *left;
  Node *right;
  T val;

  Node(T v, Node *p) :
    parent(p), left(NULL), right(NULL), val(v){}
};

struct Counter{
  int key;
  int cnt;
  Counter(int k, int c = 0) : key(k), cnt(c){}
};

inline bool operator == (const Counter &lhs, const Counter &rhs){
  return lhs.key == rhs.key;
}

inline bool operator != (const Counter &lhs, const Counter &rhs){
  return !(lhs == rhs);
}

inline bool operator < (const Counter &lhs, const Counter &rhs){
  return lhs.key < rhs.key;
}
inline bool operator > (const Counter &lhs, const Counter &rhs){
  return rhs < lhs;
}
inline bool operator <= (const Counter &lhs, const Counter &rhs){
  return !(rhs < lhs);
}
inline bool operator >= (const Counter &lhs, const Counter &rhs){
  return !(lhs < rhs);
}

inline Counter &operator += (Counter &lhs, const Counter &rhs){
  lhs.cnt += rhs.cnt;
  return lhs;
}

typedef Node<Counter> Nd;

Nd *push(Nd *root, Counter val, Nd *parent = NULL){
  if(root == NULL) return new Nd(val, parent);
  if(root->val == val){
    root->val += val;
  }else{
    if(root->val < val){
      root->right = push(root->right, val, root);
    }
    else{
      root->val += val;
      root->left = push(root->left,  val, root);
    }
  }
  return root;
}

void traverse(Nd *root, int depth = 0){
  if(root == NULL) return;
  traverse(root->left, depth+1);
  REP(i,depth) cout << " ";
  cout << root->val.key << ": " << root->val.cnt << endl;
  traverse(root->right, depth+1);
}

int countUnder(Nd *root, int key){
  if(root == NULL) return 0;
  if(key < root->val.key){
    return countUnder(root->left, key);
  }else{
    return root->val.cnt + countUnder(root->right, key);
  }
}

vector<int> x;
vector<int> level;
vector<vector<int> > prevs;
vector<vector<int> > g;
vector<Nd*> table;
vector<Nd*> table2;
Nd *root = NULL;

Nd *gen(Nd *root, Counter val){
  Nd *ret = NULL;
  Nd *now = ret;

  do{
    Nd *next = new Nd(root->val, now);
    next->left  = root->left;
    next->right = root->right;

    if(next->val >= val)
      next->val.cnt++;

    if(now == NULL){
      ret = now = next;
    }else{
      if(now->val < val){
	now->right = next;
      }else{
	now->left  = next;
      }
    }

    now = next;
    if(root->val < val) root = root->right;
    else                root = root->left;
  }while(root);

  return ret;
}

Nd *gen2(Nd *root, Counter val){
  Nd *ret = NULL;
  Nd *now = ret;

  do{
    Nd *next = new Nd(root->val, now);
    next->left  = root->left;
    next->right = root->right;

    if(next->val == val)
      next->val.cnt++;

    if(now == NULL){
      ret = now = next;
    }else{
      if(now->val < val){
	now->right = next;
      }else{
	now->left  = next;
      }
    }

    now = next;
    if(root->val < val) root = root->right;
    else                root = root->left;
  }while(root);

  return ret;
}

void calc(int pos, int prev, int l = 0){
  // printf("root: %x, val: %d\n", (unsigned int)root, x[pos]);
  table[pos]  =  gen(prev != -1 ? table[prev]  : root, Counter(x[pos], 1));
  table2[pos] = gen2(prev != -1 ? table2[prev] : root, Counter(x[pos], 1));
  // traverse(table[pos]);
  prevs[pos][0] = prev;
  level[pos] = l;

  REP(i, g[pos].size()) if(prev != g[pos][i]){
    calc(g[pos][i], pos, l + 1);
  }
}

int parentOf(int a, int b){
  if(level[a] > level[b]) swap(a, b);

  int diff = level[b] - level[a];
  REP(i,20) if(diff & (1 << i)){
    b = prevs[b][i];
  }

  assert(level[b] == level[a]);
  if(a == b) return a;

  for(int i = 19; i >= 0; i--){
    if(prevs[a][i] != -1){
      if(prevs[a][i] == prevs[b][i]){
	// do nothing
      }else{
	a = prevs[a][i];
	b = prevs[b][i];
	i++;
      }
    }
  }

  if(a == b) return a;
  else return prevs[a][0];
}

int find_min(int v, int w, int pr, int l){
  Nd *vr = table2[v];
  Nd *wr = table2[w];
  Nd *prr = table2[pr];
  Nd *pprr = prevs[pr][0] == -1 ? NULL : table2[prevs[pr][0]];
  Nd *tmp = prevs[pr][0] == -1 ? NULL : table[prevs[pr][0]];;

  while(vr){
    int val = vr->val.key;
    int cnt = countUnder(table[v], val) + countUnder(table[w], val)
      - countUnder(table[pr], val) - countUnder(tmp, val);

    int ocnt = vr->val.cnt + wr->val.cnt - prr->val.cnt;
    if(pprr) ocnt -= pprr->val.cnt;

    // printf("val: %d  cnt: %d  ocnt: %d\n", val, cnt, ocnt);

    if(ocnt > 0 && cnt >= l && cnt - ocnt + 1 <= l) return val;

    if(cnt >= l){
      vr = vr->left;
      wr = wr->left;
      prr = prr->left;
      if(pprr) pprr = pprr->left;
    }else{
      vr = vr->right;
      wr = wr->right;
      prr = prr->right;
      if(pprr) pprr = pprr->right;
    }
  }

  return 0;
}

int main(){
  int N = getInt();
  int Q = getInt();

  x.resize(N);
  level.resize(N);
  prevs = vector<vector<int> >(N, vector<int>(20, -1));
  g.resize(N);
  table.resize(N);
  table2.resize(N);

  REP(i,N){ x[i] = getInt(); }
  REP(i,N-1){
    int a = getInt() - 1;
    int b = getInt() - 1;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  
  vector<int> y = x;
  {
    // Construct
    random_shuffle(y.begin(), y.end());
    FOR(it, y){ root = push(root, Counter(*it, 0)); }
  }

  {
    // Calc all
    calc(0, -1, 0);

    for(int l = 1; l < 20; l++){
      REP(i,N){
	if(prevs[i][l - 1] != -1 && prevs[prevs[i][l - 1]][l - 1] != -1){
	  prevs[i][l] = prevs[prevs[i][l - 1]][l - 1];
	}
      }
    }

    /*
    REP(i,N) printf("level[%d] = %d\n", i + 1, level[i]);
    REP(i,N){
      printf("prevs[%d]: ", i + 1);
      REP(j, 20) printf("%d ", 1 + prevs[i][j]);
      puts("");
    }
    REP(i,N) for(int j = i + 1; j < N; j++)
      printf("%d %d : %d\n", i + 1, j + 1, parentOf(i, j) + 1);

    REP(i,N){ printf("%d:\n", i + 1); traverse(table2[i]); }
    */
  }

  sort(y.begin(), y.end());

  REP(i, Q){
    int v = getInt() - 1;
    int w = getInt() - 1;
    int l = getInt();

    int pr = parentOf(v, w);
    int ans = find_min(v, w, pr, l);

    printf("%d\n", ans);
  }
  
  return 0;
}

Measured memory_bytes: 126000