#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
void Solve() {
static int t = 0; ++t;
int n, m; cin >> n >> m;
vector<vector<pair<int, int>>> src(n);
if(t == 2969) cerr << n << " " << m << endl;
for(int i = 1, u, v; i <= m; ++i) {
cin >> u >> v, --u, --v,
src[u].emplace_back(v, i),
src[v].emplace_back(u, i);
if(t == 2969) cerr << u + 1 << " " << v + 1 << endl;
}
vector<int> a(n), L(n + 1), R(n + 1); int h = n;
for(int i = 0; i < n; ++i) cin >> a[i];
if(t == 2969) for(int i = 0; i < n; ++i) cerr << a[i] << " ";
sort(a.begin(), a.end()), R[n - 1] = R[n] = n;
for(int i = n; --i > 0;) R[i - 1] = a[i] == a[i - 1] ? R[i] : i;
reverse(a.begin(), a.end()), L[n - 1] = L[n] = n;
for(int i = n; --i > 0;) L[i - 1] = a[i] == a[i - 1] ? L[i] : i;
int t; vector<vector<int>> G, bcc;
{ // e-bcc tarjan
vector<int> id(n), lw(n), bel(n);
int dft = 0; t = -1; vector<int> s;
const auto &dfs = [&](auto &&sf, int x, int f) -> void {
id[x] = lw[x] = ++dft, s.push_back(x);
for(const auto [v, e] : src[x]) if(e != f) {
if(id[v]) lw[x] = min(lw[x], id[v]);
else sf(sf, v, e), lw[x] = min(lw[x], lw[v]);
}
if(id[x] != lw[x]) return; ++t;
for(int q = -1; q != x; )
bel[q = s.back()] = t, s.pop_back();
};
dfs(dfs, 0, -1), G.resize(++t), bcc.resize(t);
for(int i = 0; i < n; ++i) bcc[bel[i]].push_back(i);
for(int i = 0, I, J; i < n; ++i)
for(const auto &[j, e] : src[i])
if((I = bel[i]) < (J = bel[j]))
G[I].push_back(J), G[J].push_back(I);
}
vector<int> w(t), Q(t); vector<pair<int, int>> f(t), g(t);
for(int i = 0; i < t; ++i) w[i] = bcc[i].size();
const auto &print = [&](int u, int m, int v) {
if(!~u) u = 0; if(!~m) m = 0; if(!~v) v = 0;
puts("Yes"); vector<int> ret(n), s(t); s[m] = 1;
for(int i = u; i != m; i = Q[i]) s[i] = 1;
for(int i = v; i != m; i = Q[i]) s[i] = 1;
const auto &dfs = [&](auto &&sf, int x, int q) -> void {
if(~q) for(const int y : bcc[x]) ret[y] = a[--h];
for(int y : G[x]) if(y != q && !s[y]) sf(sf, y, x);
if(!~q) for(const int y : bcc[x]) ret[y] = a[--h];
for(int y : G[x]) if(y != q && s[y]) sf(sf, y, x);
};
dfs(dfs, u, -1);
for(int i = 0; i < n; ++i)
printf("%d%c", ret[i], " \n"[i == n - 1]);
};
const auto &dfs = [&](auto &&sf, int x, int q) -> int {
for(int i : G[x]) if(i != q)
{ if(sf(sf, i, Q[i] = x)) return 1; w[x] += w[i]; }
if(R[0] >= w[x]) f[x] = {1, x};
else for(int i : G[x]) if(i != q)
if(f[i].fi && R[w[i]] >= w[x]) { f[x] = {1, f[i].se}; break; }
if(L[0] >= w[x]) g[x] = {1, x};
else for(int i : G[x]) if(i != q)
if(g[i].fi && L[w[i]] >= w[x]) { g[x] = {1, g[i].se}; break; }
if(f[x].fi && R[w[x]] == n) return print(f[x].se, q, q), 1;
if(g[x].fi && L[w[x]] == n) return print(q, q, g[x].se), 1;
array<int, 3> p0 = {0, 0, 0}, p1 = {0, 0, 0};
for(int i : G[x]) if(i != q) {
array<int, 3> t = {f[i].fi, w[i], i};
if(t > p0) p1 = p0, p0 = t; else if(t > p1) p0 = t;
}
for(int i : G[x]) if(i != q && g[i].fi) {
if(p0[0] && i != p0[2] && R[p0[1]] >= n - w[i])
return print(f[p0[2]].se, x, g[i].se), 1;
if(p1[0] && i != p1[2] && R[p1[1]] >= n - w[i])
return print(f[p1[2]].se, x, g[i].se), 1;
}
return 0;
};
if(!dfs(dfs, 0, -1)) puts("No");
}
int main() {
cin.tie(0)->sync_with_stdio(0);
int T; cin >> T; while(T--) Solve();
}