#include <bits/stdc++.h>
using namespace std;
#define pb push_back
const int N = 4e5 + 5;
int n, rt, a[N], b[N], stk[N], top, pre[N], suf[N];
vector <int> adj[N];
void dfs(int u, int fa, int step) {
	a[step] = b[u];
	for (auto v : adj[u]) if (v != fa) dfs(v, u, step + 1);
}
void func() {
	scanf("%d%d", &n, &rt);
	for (int i = 1; i <= n; i++) adj[i].clear();
	for (int i = 1; i <= n; i++) scanf("%d", &b[i]);
	for (int i = 1, x, y; i < n; i++) {
		scanf("%d%d", &x, &y);
		adj[x].pb(y), adj[y].pb(x);
	}
	dfs(rt, 0, 1);
	for (int i = 1; i <= n; i++) {
		while (top && a[stk[top]] <= )
	}
}

int main() {
	int t; scanf("%d", &t);
	while (t--) func();
	return 0;
}
