#include<iostream> #include<cstdio> #define MAX_N 200 #define MAX_M 10000 usingnamespace std; int n, m, p[MAX_N+5], l[MAX_M+5], r[MAX_M+5], fa[MAX_M*2+5]; voidinit(){for (int i = 0; i < 2*m; i++) fa[i] = i;} intgetf(int x){return fa[x] == x ? x : fa[x] = getf(fa[x]);} voidmerge(int a, int b){a = getf(a), b = getf(b); if (a != b) fa[a] = b;} intmain(){ int T; scanf("%d", &T); while (T--) { scanf("%d%d", &n, &m), init(); bool flag = true; for (int i = 0; i < m; i++) scanf("%d%d", &l[i], &r[i]); for (int i = 0, x; i < n; i++) scanf("%d", &x), p[x] = i; for (int i = 0; i < m; i++) l[i] = p[l[i]], r[i] = p[r[i]]; for (int i = 0; i < m; i++) if (l[i] > r[i]) swap(l[i], r[i]); for (int i = 1; i < m; i++) for (int j = 0; j < i; j++) if ((l[i] < l[j] && r[i] > l[j] && r[i] < r[j]) || (l[i] > l[j] && l[i] < r[j] && r[i] > r[j])) merge(i*2, j*2+1), merge(i*2+1, j*2); for (int i = 0; i < m; i++) flag &= (getf(i*2) != getf(i*2+1)); printf("%s\n", flag ? "YES" : "NO"); } return0; }