#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>

constexpr int N = 400005;
constexpr int p = 998244353;

int add(int x, int y) { return (x += y) >= p ? x - p : x; }
int mul(int x, int y) { return static_cast<unsigned long long>(x) * y % p; }
int power(int x, int y) { int ans = 1; for (; y; y >>= 1) { if (y & 1) ans = mul(ans, x); x = mul(x, x); } return ans; }

int T, n, rt;
int a[N];
std::vector<int> v[N];
int fac[N], inv[N];
int fa[N], min[N];
int totans;

int C(int n, int m) { return mul(fac[n], mul(inv[m], inv[n - m])); }
int invC(int n, int m) { return mul(inv[n], mul(fac[m], fac[n - m])); }

typedef std::vector<std::pair<int, int>> comb;

comb fix(comb a) {
    std::sort(a.begin(), a.end());
    comb ans;
    for (auto [val, pos] : a)
        if (ans.empty() || val != ans.back().first) ans.emplace_back(val, pos);
        else ans.back().second = add(ans.back().second, pos);
    return ans;
}

comb merge(const comb& a, const comb& b) {
    std::vector<int> suf1(a.size()), suf2(b.size());
    suf1.back() = a.back().second;
    for (int i = a.size() - 2; i >= 0; --i) suf1[i] = add(suf1[i + 1], a[i].second);
    suf2.back() = b.back().second;
    for (int i = b.size() - 2; i >= 0; --i) suf2[i] = add(suf2[i + 1], b[i].second);
    comb res;
    for (auto [val, pos] : a) {
        int index = std::lower_bound(b.begin(), b.end(), std::make_pair(val, 0)) - b.begin();
        if (index < b.size()) res.emplace_back(val, mul(pos, suf2[index]));
    }
    for (auto [val, pos] : b) {
        int index = std::lower_bound(a.begin(), a.end(), std::make_pair(val + 1, 0)) - a.begin();
        if (index < a.size()) res.emplace_back(val, mul(pos, suf1[index]));
    }
    return fix(res);
}

int get(const comb& a) {
    int ans = 0;
    for (auto [val, pos] : a) ans = add(ans, mul(val, pos));
    return ans;
}

void dfs(int x, int f) {
    fa[x] = f;
    min[x] = a[x];
    for (int i : v[x])
        if (i != f) {
            dfs(i, x);
            min[x] = std::min(min[x], min[i]);
        }
}

comb tof[N];

void dfs2(int x) {
    std::vector<std::pair<int, int>> list;
    for (int i : v[x])
        if (i != fa[x])
            list.emplace_back(min[i], i);
    std::sort(list.begin(), list.end());
    int cnt = list.size();
    int tmpinv = power(cnt, p - 2);
    for (int i : v[x])
        if (i != fa[x]) {
            std::vector<std::pair<int, int>> list2;
            for (auto [val, index] : list)
                if (index != i)
                    list2.emplace_back(val, index);
            tof[i].clear();
            tof[i].emplace_back(1000000000, tmpinv);
            for (int j = 0; j < cnt - 1; ++j) {
                int rest = cnt - 2 - j;
                int sum = 0;
                for (int k = 0; k <= rest; ++k) sum = add(sum, mul(C(rest, k), invC(cnt - 1, k + 1)));
                sum = mul(sum, tmpinv);
                tof[i].emplace_back(list2[j].first, sum);
            }
            tof[i] = fix(tof[i]);
            dfs2(i);
        }
}

comb now[N];

void solve(int x, int root) {
    comb tmp;
    tmp.emplace_back(a[x], 1);
    if (x == root) now[x] = tmp;
    else {
        now[x] = merge(tof[x], tmp);
        now[x] = merge(now[x], now[fa[x]]);
    }
    totans = add(totans, get(now[x]));
    for (int i : v[x])
        if (i != fa[x]) {
            solve(i, root);
        }
}

int main() {
    freopen("dfs.in", "r", stdin);
    freopen("dfs.out", "w", stdout);
    std::ios::sync_with_stdio(false), std::cin.tie(nullptr);
    std::cin >> T;
    while (T--) {
        std::cin >> n >> rt;
        fac[0] = 1;
        for (int i = 1; i <= n; ++i) {
            std::cin >> a[i];
            v[i].clear();
            fac[i] = mul(fac[i - 1], i);
        }
        inv[n] = power(fac[n], p - 2);
        for (int i = n; i; --i) inv[i - 1] = mul(inv[i], i);
        for (int i = 1, x, y; i < n; ++i) {
            std::cin >> x >> y;
            v[x].push_back(y);
            v[y].push_back(x);
        }
        dfs(rt, 0);
        dfs2(rt);
        totans = 0;
        for (int i = 1; i <= n; ++i) {
            solve(i, i);
        }
        std::cout << totans << '\n';
    }
    return 0;
}
