#include <bits/stdc++.h>

template<unsigned P>
class modint {
  using mint = modint<P>;

  unsigned v;

public:
  constexpr modint() : v() {}

  template<typename T,
           typename std::enable_if<std::is_integral<T>::value &&
                                       std::is_signed<T>::value,
                                   bool>::type = true>
  constexpr modint(T t_v) : v() {
    long long tmp = t_v;
    tmp %= P;
    if (tmp < 0) {
      tmp += P;
    }
    v = tmp;
  }

  template<typename T,
           typename std::enable_if<std::is_integral<T>::value &&
                                       std::is_unsigned<T>::value,
                                   bool>::type = true>
  constexpr modint(T t_v) : v() {
    v = t_v % P;
  }

  static constexpr unsigned mod() {
    return P;
  }

  static constexpr mint raw(unsigned t_v) {
    mint res;
    res.v = t_v;
    return res;
  }

  constexpr unsigned val() {
    return v;
  }

  constexpr mint &operator+=(const mint &rhs) {
    v < P - rhs.v ? v += rhs.v : v -= P - rhs.v;
    return *this;
  }

  constexpr mint &operator-=(const mint &rhs) {
    v < rhs.v ? v += P - rhs.v : v -= rhs.v;
    return *this;
  }

  constexpr mint &operator*=(const mint &rhs) {
    v = (unsigned long long)(v) * rhs.v % P;
    return *this;
  }

  constexpr mint pow(unsigned long long b) const {
    mint a = *this, s = 1;
    while (b) {
      if (b & 1) {
        s *= a;
      }
      a *= a;
      b >>= 1;
    }
    return s;
  }

  constexpr mint inv() const {
    return pow(P - 2);
  }

  constexpr friend mint operator+(const mint &lhs, const mint &rhs) {
    return mint(lhs) += rhs;
  }

  constexpr friend mint operator-(const mint &lhs, const mint &rhs) {
    return mint(lhs) -= rhs;
  }

  constexpr friend mint operator*(const mint &lhs, const mint &rhs) {
    return mint(lhs) *= rhs;
  }

  constexpr friend bool operator==(const mint &lhs, const mint &rhs) {
    return lhs.v == rhs.v;
  }

  friend std::istream &operator>>(std::istream &in, mint &x) {
    return in >> x.v;
  }

  friend std::ostream &operator<<(std::ostream &out, const mint &x) {
    return out << x.v;
  }
};

using mint = modint<998244353>;

int main() {
  std::ifstream fin("dfs.in");
  std::ofstream fout("dfs.out");

  int T;
  fin >> T;
  while (T--) {
    int n, rt;
    fin >> n >> rt;
    --rt;
    std::vector<int> a(n);
    for (int i = 0; i < n; ++i) {
      fin >> a[i];
    }
    std::vector<std::vector<int>> E(n);
    for (int i = 0; i < n - 1; ++i) {
      int u, v;
      fin >> u >> v;
      --u, --v;
      E[u].push_back(v);
      E[v].push_back(u);
    }

    auto val = a;
    std::sort(val.begin(), val.end());
    val.erase(std::unique(val.begin(), val.end()), val.end());
    val.insert(val.begin(), 0);
    int m = val.size();
  
    for (int i = 0; i < n; ++i) {
      a[i] = std::lower_bound(val.begin(), val.end(), a[i]) - val.begin();
    }

    std::vector<int> min(n);

    auto get_min = [&](auto &self, int u, int fa) -> void {
      if (fa != -1) {
        E[u].erase(std::find(E[u].begin(), E[u].end(), fa));
      }
      min[u] = a[u];
      for (int v : E[u]) {
        self(self, v, u);
        min[u] = std::min(min[u], min[v]);
      }
    };

    get_min(get_min, rt, -1);

    std::vector<mint> inv(n + 1);
    inv[1] = 1;
    for (int i = 2; i <= n; ++i) {
      inv[i] = inv[mint::mod() % i] * mint::raw(mint::mod() - mint::mod() / i);
    }

    mint ans = 0;
    
    if ((int)E[rt].size() == n - 1) {
      std::vector<int> cnt(m);
      for (int i = 0; i < n; ++i) {
        if (i != rt) {
          ++cnt[a[i]];
        }
      }
      int tot = cnt[0];
      for (int B = 1; B < m; ++B) {
        mint sum = 0;
        if (a[rt] >= B) {
          sum += (n - 1 - tot) * inv[tot + 1];
        }
        ans += sum * (val[B] - val[B - 1]);
        tot += cnt[B];
      }
    } else {
      for (int B = 1; B < m; ++B) {
        mint sum = 0;

        auto dfs = [&](auto &self, int u, mint now) -> void {
          if (a[u] >= B) {
            sum += now;
            int cnt = 0;
            for (int v : E[u]) {
              cnt += min[v] < B;
            }
            for (int v : E[u]) {
              int t = cnt - (min[v] < B) + 1;
              self(self, v, now * inv[t] + inv[t]);
            }
          } else {
            for (int v : E[u]) {
              self(self, v, mint());
            }
          }
        };
        
        dfs(dfs, rt, mint());
        ans += sum * (val[B] - val[B - 1]);
      }
    }

    for (int i = 0; i < n; ++i) {
      ans += val[a[i]];
    }
    fout << ans << "\n";
  }
}
