template <classT> voidread(T &r){ r = 0; int ch = getchar(), f = 0; while (!isdigit(ch)) { if (ch == 45) f ^= 1; ch = getchar(); } while (isdigit(ch)) (r *= 10) += ch - 48, ch = getchar(); if (f) r = -r; }
constint maxm = 1e4 + 5, maxn = 2e2 + 5; int t, n, m; int u[maxm], v[maxm], h[maxn], ih[maxn]; int f[maxm << 1];
intfind(int x){ return x == f[x] ? x : f[x] = find(f[x]); }
intmain(){ read(t); while (t--) { read(n); read(m); for (int i = 1; i <= m * 2; i++) f[i] = i; for (int i = 1; i <= m; i++) { read(u[i]); read(v[i]); } for (int i = 1; i <= n; i++) { read(h[i]); ih[h[i]] = i; } if (m > 3 * n - 6) { printf("NO\n"); continue; } for (int i = 1; i <= m; i++) { u[i] = ih[u[i]], v[i] = ih[v[i]]; if (u[i] > v[i]) swap(u[i], v[i]); } for (int i = 1; i <= m; i++) { for (int j = i + 1; j <= m; j++) { if ((u[j] < u[i] && u[i] < v[j] && v[j] < v[i]) || (u[i] < u[j] && u[j] < v[i] && v[i] < v[j])) { int i1 = find(i), j2 = find(j + m); if (j2 != i1) f[j2] = i1; int j1 = find(j), i2 = find(i + m); if (j1 != i2) f[j1] = i2; } } } for (int i = 1; i <= m; i++) { if (find(i) == find(i + m)) { printf("NO\n"); break; } if (i == m) printf("YES\n"); } } return0; }