#include <bits/stdc++.h>
using namespace std;
constexpr int maxn = 1e6 + 10;
vector<int> G[maxn];
bool dfs_path(int n, int pre, int b, vector<int>& path) {
  path.push_back(n);
  if (n == b) return true;
  for (int to : G[n]) {
    if (to == pre) continue;
    if (dfs_path(to, n, b, path)) return true;
  }
  path.pop_back();
  return false;
}
pair<int, int> len[maxn][4];
void dfs1(int n, int pre) {
  for (int to : G[n]) {
    if (to == pre) continue;
    dfs1(to, n);
    len[n][3] = make_pair(len[to][0].first + 1, to);
    sort(len[n], len[n] + 4, greater<pair<int, int> >());
  }
}
vector<int> path;
int point = 0;
void dfs2(int n, int pre, int L) {
  len[n][3] = make_pair(L, -1);
  sort(len[n], len[n] + 4, greater<pair<int, int> >());
  bool t = true;
  for (int i = 0; i < 3; i++)
    if (len[n][i].first < path.size() - 1) t = false;
  if (t) point = n;
  for (int to : G[n]) {
    if (to == pre) continue;
    int nl = L;
    if (to == len[n][0].second)
      nl = max(nl, len[n][1].first);
    else
      nl = max(nl, len[n][0].first);
    dfs2(to, n, nl + 1);
  }
}
int deep[maxn], fa[maxn];
void dfs_deep(int n, int pre) {
  fa[n] = pre;
  for (int to : G[n]) {
    if (to == pre) continue;
    dfs_deep(to, n);
    deep[n] = max(deep[n], deep[to] + 1);
  }
}
int main() {
  int T;
  cin >> T;
  while (T--) {
    int N, a, b;
    cin >> N >> a >> b;
    for (int i = 0; i <= N; i++) {
      G[i].clear();
      for (int j = 0; j < 4; j++) len[i][j] = make_pair(0, 0);
      deep[i] = 0;
      fa[i] = 0;
    }
    for (int i = 1; i < N; i++) {
      int u, v;
      cin >> u >> v;
      G[u].push_back(v);
      G[v].push_back(u);
    }
    point = 0;
    path.clear();
    dfs_path(a, -1, b, path);
    dfs1(1, -1);
    dfs2(1, -1, 0);
    if (point == 0) {
      cout << "NO\n";
      continue;
    }
    dfs_deep(point, -1);
    int lca = a;
    int p = 0;
    while (p + 1 < path.size() && fa[lca] == path[++p]) lca = fa[lca];
    fa[lca] = lca;
    int pl = a, pr = b;
    bool judge = false;
    int tl = 0, tr = -1;
    int cnt = 0;
    while (true) {
      if (++cnt > N) break;
      for (int i = 1; i <= deep[pl] - tl; i++) pr = fa[pr];
      tr = deep[pl];
      if (pr == lca) judge = true;
      for (int i = 1; i <= deep[pr] - tr; i++) pl = fa[pl];
      tl = deep[pr];
      if (pl == fa[pl]) judge = true;
      if (judge) break;
    }
    cout << (judge ? "YES\n" : "NO\n");
  }
}
