// wei sha wo xie shen me ti dou you chang you tiao bu chu lai a 
// /tuu/tuu/tuu

#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5, mod = 998244353;
int T, n, m, root, f[N], a[N], inv[N], ban[N], hvb[N], fa[N];
vector<int> g[N];
void dfs(int u) {
  int cnt = 0;
  f[u] = !ban[u], hvb[u] = ban[u];
  for (auto v : g[u]) if (v != fa[u]) {
    fa[v] = u, dfs(v), cnt += hvb[v], hvb[u] |= hvb[v];
  }
  for (auto v : g[u]) if (v != fa[u]) {
    (f[u] += 1ll * f[v] * inv[cnt + (!hvb[v])] % mod) %= mod;
  }
  if (ban[u]) f[u] = 0;
}
void solve() {
  scanf("%d%d", &n, &root);
  vector<int> d; d.push_back(0);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    d.push_back(a[i]);
    g[i].clear(), fa[i] = 0;
  }
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    g[u].push_back(v);
    g[v].push_back(u);
  }
  sort(d.begin(), d.end());
  d.resize(m = unique(d.begin(), d.end()) - d.begin());
  inv[1] = 1;
  for (int i = 2; i <= n; i++) inv[i] = 1ll * (mod - mod / i) * inv[mod % i] % mod;
  for (int i = 1; i <= n; i++) {
    a[i] = lower_bound(d.begin(), d.end(), a[i]) - d.begin();
  }
  int ans = 0;
  for (int i = 1; i < m; i++) {
    for (int j = 1; j <= n; j++) ban[j] = (a[j] < i), f[j] = 0;
    dfs(root);
    int ret = 0;
    for (int j = 1; j <= n; j++) (ret += f[j]) %= mod;
    (ans += 1ll * ret * (d[i] - d[i - 1]) % mod) %= mod;
  }
  printf("%d\n", ans);
}
int main() {
  freopen("dfs.in", "r", stdin);
  freopen("dfs.out", "w", stdout);
  scanf("%d", &T);
  while (T--) solve();
  return 0;
}
