#include <bits/stdc++.h>
#define ll long long
#define sz(a) int((a).size())
using namespace std;
const int N = 4e5 + 10, M = N * 80;
const int P = 998244353;
int n, rt, a[N], id[N], rid[N], dp[N], res[N], inv[N];
vector<int> g[N];
struct node {
    int a, b;
    node(int A = 0, int B = 0) {a = A, b = B; }
    friend node operator * (const node a, const node b) {
        return node((ll)a.a * b.a % P, ((ll)a.b * b.a % P + b.b) % P);
    }
    friend node operator + (const node a, const node b) {
        return node((a.a + b.a) % P, (a.b + b.b) % P);
    }
    friend bool operator == (const node a, const node b) {
        return a.a == b.a && a.b == b.b;
    }
};
int ls[M], rs[M], tot = 0;
node tag[M], htag[M];
int stk[M], top = 0;
void del(int x) {stk[++top] = x; }
int nwd() {
    int u = top ? stk[top--] : ++tot;
    ls[u] = rs[u] = 0;
    tag[u] = node(1, 0), htag[u] = node(0, 0);
    return u;
}
int tim[N];
#define mid ((l + r) >> 1)
void down(int &x, int l, int r, node v, node h) {
    if(!x) x = nwd();
    htag[x] = htag[x] + tag[x] * h;
    tag[x] = tag[x] * v;
}
void pushdown(int x, int l, int r) {
    if(tag[x] == node(1, 0) && htag[x] == node(0, 0)) return;
    down(ls[x], l, mid, tag[x], htag[x]), down(rs[x], mid + 1, r, tag[x], htag[x]);
    tag[x] = node(1, 0), htag[x] = node(0, 0);
}
void modify(int &p, int l, int r, int L, int R, node v, node h) {
    if(!p) p = nwd();
    if(L > R) return;
    if(L <= l && r <= R) {
        down(p, l, r, v, h);
        return;
    }
    pushdown(p, l, r);
    if(L <= mid) modify(ls[p], l, mid, L, R, v, h);
    if(R > mid) modify(rs[p], mid + 1, r, L, R, v, h);
    return;
}
int isl(int x) {return !ls[x] && !rs[x]; }
int merge(int a, int b, int l, int r) {
    if(!a || !b) return a + b;
    if(isl(a) && isl(b)) {
        tag[a] = tag[a] + tag[b];
        htag[a] = htag[a] + htag[b];
        tag[a].a = htag[a].a = 0;
        del(b);
        return a;
    }
    pushdown(a, l, r), pushdown(b, l, r);
    ls[a] = merge(ls[a], ls[b], l, mid);
    rs[a] = merge(rs[a], rs[b], mid + 1, r);
    del(b);
    return a;
}
int rt0[N], siz[N];
void DFS(int &x, int l, int r) {
    if(l == r) {
        res[l] = htag[x].b;
        return;
    }
    pushdown(x, l, r);
    DFS(ls[x], l, mid), DFS(rs[x], mid + 1, r);
    return;
}
void dfs(int u, int fa) {
    rt0[u] = 0;
    tim[u] = rid[u];
    siz[u] = 1;
    vector<int> son;
    for(auto v : g[u]) {
        if(v == fa) continue;
        dfs(v, u);
        son.push_back(v);
        siz[u] += siz[v];
        modify(rt0[v], 1, n, 1, tim[v], node(0, 0), node(0, 0));
        rt0[u] = merge(rt0[u], rt0[v], 1, n);
        tim[u] = min(tim[u], tim[v]);
    }
    sort(son.begin(), son.end(), [&](int x, int y) {return tim[x] < tim[y]; });
    int lst = 0, sum = siz[u] - 1;
    for(int i = 0; i < sz(son); i++) {
        if(lst >= rid[u]) break;
        modify(rt0[u], 1, n, lst + 1, tim[son[i]], node(inv[i], (ll)sum * inv[i + 1] % P), node(0, 0));
        lst = tim[son[i]], sum -= siz[son[i]];
    }
    if(lst <= rid[u]) modify(rt0[u], 1, n, lst + 1, n, node(inv[sz(son)], (ll)sum * inv[sz(son) + 1] % P), node(0, 0));
    modify(rt0[u], 1, n, 1, n, node(1, 1), node(0, 0));
    modify(rt0[u], 1, n, rid[u] + 1, n, node(0, 0), node(0, 0));
    modify(rt0[u], 1, n, 1, n, node(1, 0), node(1, 0));
    return;
}
void solve() {
    top = 0;
    tot = 0;
    scanf("%d%d", &n, &rt);
    for(int i = 1; i <= n; i++) g[i].clear();
    for(int i = 1; i <= n; i++) scanf("%d", &a[i]), id[i] = i;
    for(int i = 1, u, v; i < n; i++) {
        scanf("%d%d", &u, &v);
        g[u].push_back(v), g[v].push_back(u);
    }
    sort(id + 1, id + n + 1, [&](int x, int y) {return a[x] < a[y]; });
    for(int i = 1; i <= n; i++) rid[id[i]] = i;
    for(int i = 0; i <= n + 1; i++) res[i] = 0;
    dfs(rt, 0);
    DFS(rt0[rt], 1, n);
    for(int i = 1; i <= n; i++) (res[i] += P - res[i + 1]) %= P;
    int ans = 0;
    for(int i = 1; i <= n; i++) (ans += (ll)res[i] * a[id[i]] % P) %= P;
    printf("%d\n", ans);
    return;
}
void init(int n) {
    inv[1] = 1;
    for(int i = 2; i <= n; i++) inv[i] = (ll)inv[P % i] * (P - P / i) % P;
}
int main() {
    freopen("dfs.in", "r", stdin);
    freopen("dfs.out", "w", stdout);
    init(N - 10);
    int T;
    for(scanf("%d", &T); T--; ) solve();
}