#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
inline int read() {
  char c = getchar();
  int x = 0;
  bool f = 0;
  for (; !isdigit(c); c = getchar()) f ^= !(c ^ 45);
  for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
  if (f) x = -x;
  return x;
}
int n, m, s, t;
struct edge {
  int to, nxt;
} e[1000005 << 1];
int tot, head[1000005];
inline void adde(int u, int v) {
  e[++tot] = (edge){v, head[u]};
  head[u] = tot;
}
struct threeint {
  int x1, x2, x3;
  void ins(int x) {
    if (x > x1)
      x3 = x2, x2 = x1, x1 = x;
    else if (x > x2)
      x3 = x2, x2 = x;
    else
      x3 = max(x3, x);
  }
} l[1000005];
int fa[1000005], l1[1000005], l2[1000005], dep[1000005];
void dfs1(int u, int pa) {
  dep[u] = dep[pa] + 1;
  for (int i = head[u]; i; i = e[i].nxt) {
    int v = e[i].to;
    if (v == pa) continue;
    fa[v] = u;
    dfs1(v, u);
    l1[u] = max(l1[u], l1[v]);
  }
  l1[u]++;
}
void dfs2(int u, int pa, int len) {
  int mx1 = 0, mx2 = 0;
  l2[u] = len;
  for (int i = head[u]; i; i = e[i].nxt) {
    int v = e[i].to;
    if (v == pa) continue;
    if (mx1 < l1[v])
      mx2 = mx1, mx1 = l1[v];
    else
      mx2 = max(mx2, l1[v]);
  }
  for (int i = head[u]; i; i = e[i].nxt) {
    int v = e[i].to;
    if (v == pa) continue;
    dfs2(v, u, max(len, mx1 == l1[v] ? mx2 : mx1) + 1);
  }
}
int out[1000005], mxd[1000005], len;
bool dfs(int u) {
  out[u] = 0;
  bool ht = (u == t);
  for (int i = head[u]; i; i = e[i].nxt) {
    int v = e[i].to;
    if (v == fa[u]) continue;
    if (dfs(v))
      ht = 1;
    else
      out[u] = max(out[u], out[v] + 1);
  }
  return ht;
}
bool work() {
  n = read(), s = read(), t = read();
  tot = 0;
  for (register int i = (1); i <= (n); ++i)
    head[i] = l[i].x1 = l[i].x2 = l[i].x3 = l1[i] = l2[i] = fa[i] = 0;
  for (register int i = (2); i <= (n); ++i) {
    int u = read(), v = read();
    adde(u, v), adde(v, u);
  }
  dfs1(s, 0), dfs2(s, 0, 0);
  for (register int i = (1); i <= (n); ++i) {
    if (!fa[i]) continue;
    l[fa[i]].ins(l1[i] + 1);
    l[i].ins(l2[i] + 1);
  }
  bool ok = 0;
  for (register int i = (1); i <= (n); ++i) ok |= (l[i].x3 >= dep[t]);
  if (!ok) return 0;
  dfs(s);
  mxd[len = 1] = out[t];
  while (t != s) t = fa[t], mxd[++len] = out[t];
  int tl = 1, tr = len;
  int maxl = mxd[tr] + 1, minr = len - mxd[tl];
  while (tl < tr) {
    if (tl < maxl)
      tl++, minr = min(minr, len - mxd[tl] + tl - 1);
    else if (tr > minr)
      tr--, maxl = max(maxl, mxd[tr] - len + tr + 1);
    else
      return 0;
  }
  return 1;
}
int main() {
  int T = read();
  while (T--) puts(work() ? "YES" : "NO");
  return 0;
}
