#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
#include <map>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

typedef vector<int> Edges;
typedef vector<Edges> Graph;

static const int LOG_SIZE = 17;
static const int SIZE = 1 << LOG_SIZE;
int parent[SIZE][LOG_SIZE];
int depth[SIZE];
struct LCA {
  LCA() {;}
  LCA(const Graph &g, int root) {
    int n = g.size();
    assert(n <= SIZE);
    dfs(g, root, root, 0);
    for (int iter = 0; iter < LOG_SIZE - 1; iter++) {
      for (int i = 0; i < n; i++) {
        parent[i][iter + 1] = parent[parent[i][iter]][iter];
      }
    }
  }
  void dfs(const Graph &g, int v, int p, int d) {
    depth[v] = d;
    parent[v][0] = p;
    for (Edges::const_iterator it = g[v].begin(); it != g[v].end(); it++) {
      if (*it == p) { continue; }
      dfs(g, *it, v, d + 1);
    }
  }
  int lca(int u, int v) {
    if (depth[u] > depth[v]) { swap(u, v); }
    for (int i = 0; i < LOG_SIZE; i++) {
      if (((depth[v] ^ depth[u]) >> i) & 1) { v = parent[v][i]; }
    }
    if (u == v) { return u; }
    for (int i = LOG_SIZE - 1; i >= 0; i--) {
      if (parent[u][i] != parent[v][i]) {
        u = parent[u][i];
        v = parent[v][i];
      }
    }
    return parent[u][0];
  }
};


//=========================================

struct Node {
  int number;
  int cnt;
  Node *left;
  Node *right;
  Node() {;}
  Node(int number, int cnt, Node *left, Node *right) : number(number), cnt(cnt), left(left), right(right) {;}
};

int m;
Node *PrivateCreateBaseTree(int n, int index) {
  Node *node = new Node(index + n / 2, 0, NULL, NULL);
  if (n != 1) {
    node->left  = PrivateCreateBaseTree(n / 2, index);
    node->right = PrivateCreateBaseTree(n / 2, index + n / 2);
  }
  return node;
}

Node *CreateBaseTree(int n) {
  int m = 1;
  while (m <= n) { m <<= 1; }
  return PrivateCreateBaseTree(m, 0);
}
Node *AddValue(int v, const Node *parent) {
  Node *node = new Node(parent->number, parent->cnt + 1, parent->left, parent->right);
  if (node->left == NULL) { return node; }
  if (v < node->number) {
    node->left  = AddValue(v, parent->left);
  } else {
    node->right = AddValue(v, parent->right);
  }
  return node;
}
int Search(int l, const Node *p1, const Node *p2, const Node *m1, const Node *m2) {
  if (p1->left == NULL) {
    assert(l <= p1->cnt + p2->cnt);
    return p1->number;
  }
  int lcnt = p1->left->cnt + p2->left->cnt - m1->left->cnt - m2->left->cnt ;
  if (l <= lcnt) {
    return Search(l, p1->left, p2->left, m1->left, m2->left);
  } else {
    return Search(l - lcnt, p1->right, p2->right, m1->right, m2->right);
  }
  assert(false);
  return 0xdeadbeaf;
}

//=================================

LCA lca;
vector<vector<int> > g;
map<int, int> mapto;
map<int, int> mapfrom;

int n, q;
int vs[100010];
Node *tree[100010];
Node *treeParent[100010];

void dfs(int v, int parent) {
  treeParent[v] = tree[parent];
  tree[v] = AddValue(vs[v], treeParent[v]);
  FORIT(it, g[v]) {
    if (*it == parent) { continue; }
    dfs(*it, v);
  }
}

int main() {
  scanf("%d %d", &n, &q);
  REP(i, n) {
    scanf("%d", &vs[i]);
    mapto[vs[i]] = 0;
  }
  int m = 0;
  FORIT(it, mapto) {
    mapfrom[m] = it->first;
    it->second = m;
    m++;
  }
  REP(i, n) {
    vs[i] = mapto[vs[i]];
  }
  g = Graph(n);
  REP(i, n - 1) {
    int f, t;
    scanf("%d %d", &f, &t);
    f--; t--;
    g[f].push_back(t);
    g[t].push_back(f);
  }
  lca = LCA(g, 0);
  tree[0] = treeParent[0] = CreateBaseTree(m);
  dfs(0, 0);
  REP(iter, q) {
    int f, t, l;
    scanf("%d %d %d", &f, &t, &l);
    f--; t--;
    int p = lca.lca(f, t);
    int number = Search(l, tree[f], tree[t], tree[p], treeParent[p]);
    printf("%d\n", mapfrom[number]);
  }
}

Measured memory_bytes: 66000