#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void cmin(T &a, T b) {
  ((a > b) && (a = b));
}
template <class T>
inline void cmax(T &a, T b) {
  ((a < b) && (a = b));
}
char IO;
template <class T = int>
T rd() {
  T s = 0;
  int f = 0;
  while (!isdigit(IO = getchar())) f |= IO == '-';
  do s = (s << 1) + (s << 3) + (IO ^ '0');
  while (isdigit(IO = getchar()));
  return f ? -s : s;
}
const int N = 2e5 + 10, INF = 1e9 + 10;
int n, k, a, b;
vector<int> G[N];
int mk[N], fl = 0;
int ma;
int id;
struct Node {
  int u, d;
  Node(int u = 0, int d = 0) : u(u), d(d) {}
  Node operator+(const int x) const { return Node(u, d + x); }
  int operator<(const Node x) const { return d < x.d; }
  int operator>(const Node x) const { return d > x.d; }
  int operator==(const Node x) const { return u == x.u; }
} dp[N][3], g[N];
int fa[N][20], dep[N], L[N], R[N], I[N], dfn, s[N];
void dfs(int u, int f) {
  I[L[u] = ++dfn] = u;
  dp[u][0] = dp[u][1] = dp[u][2] = Node(u, 0);
  dep[u] = dep[fa[u][0] = f] + 1;
  for (int i = 1, iend = 19; i <= iend; ++i) fa[u][i] = fa[fa[u][i - 1]][i - 1];
  for (int v : G[u])
    if (v != f) {
      dfs(v, u);
      Node t = dp[v][0] + 1;
      for (int i = 0, iend = 2; i <= iend; ++i)
        if (t > dp[u][i]) swap(dp[u][i], t);
    }
  R[u] = dfn;
}
void dfs2(int u, int f) {
  static int t[5];
  t[0] = dp[u][0].d;
  t[1] = dp[u][1].d;
  t[2] = dp[u][2].d;
  t[3] = g[u].d;
  sort(t, t + 4, greater<int>());
  mk[u] = t[2] >= k - 1;
  for (int v : G[u])
    if (v != f) {
      g[v] = max(g[u], dp[u][dp[u][0] == dp[v][0] + 1]) + 1;
      dfs2(v, u);
    }
}
int Jump(int u, int k) {
  for (int i = 0, iend = 19; i <= iend; ++i)
    if (k & (1 << i)) u = fa[u][i];
  return u;
}
int LCA(int x, int y) {
  if (dep[x] < dep[y]) swap(x, y);
  x = Jump(x, dep[x] - dep[y]);
  if (x == y) return x;
  for (int i = 19, iend = 0; i >= iend; --i)
    if (fa[x][i] != fa[y][i]) x = fa[x][i], y = fa[y][i];
  return fa[x][0];
}
int Go(int a, int b, int k) {
  int lca = LCA(a, b);
  if (dep[a] - dep[lca] < k)
    k -= dep[a] - dep[lca], a = lca;
  else
    return Jump(a, k);
  return Jump(b, (dep[b] - dep[a]) - k);
}
int Max(int a, int b) {
  if (L[a] <= L[b] && L[b] <= R[a]) {
    b = Jump(b, dep[b] - dep[a] - 1);
    return max(g[a], dp[a][dp[b][0] + 1 == dp[a][0]]).u;
  } else
    return dp[a][0].u;
}
void MarkTree(int a, int b) {
  if (L[a] <= L[b] && L[b] <= R[a]) {
    assert(a != b);
    b = Jump(b, dep[b] - dep[a] - 1);
    s[1]++, s[L[b]]--, s[R[b] + 1]++, s[n + 1]--;
  } else {
    s[L[a]]++, s[R[a] + 1]--;
  }
}
int A[N], C;
int main() {
  for (int _ = 1, _end = rd(); _ <= _end; ++_) {
    n = rd(), a = rd(), b = rd();
    for (int i = 1, iend = n; i <= iend; ++i) G[i].clear();
    for (int i = 2, iend = n; i <= iend; ++i) {
      int u = rd(), v = rd();
      G[u].push_back(v), G[v].push_back(u);
    }
    dfn = 0, dfs(a, 0), k = dep[b], g[a] = Node(a, 0), dfs2(a, 0);
    for (int i = 0, iend = n; i <= iend; ++i) s[i] = 0;
    for (int i = 1, iend = n * 2; i <= iend; ++i) {
      swap(a, b);
      MarkTree(a, b), MarkTree(b, a);
      int c = Max(a, b), d = Go(c, b, k - 1);
      a = c, b = d;
    }
    int fl = 0;
    for (int i = 1, iend = n; i <= iend; ++i) s[i] += s[i - 1];
    for (int i = 1, iend = n; i <= iend; ++i)
      if (s[L[i]] && mk[i]) fl = 1;
    puts(fl ? "YES" : "NO");
  }
}
