#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0;
  char ch = getchar();
  bool d = 1;
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') d = 0;
  for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
  return d ? x : -x;
}
inline void write(long long x) {
  if (x < 0) x = -x, putchar('-');
  if (x >= 10) write(x / 10);
  putchar('0' + x % 10);
}
inline void writeln(long long x) {
  write(x);
  puts("");
}
inline void writep(long long x) {
  write(x);
  putchar(' ');
}
inline unsigned long long rnd() {
  return ((unsigned long long)rand() << 30 ^ rand()) << 4 | rand() % 4;
}
const int N = 1e5 + 5;
int mx[N], cmx[N], f[N], cnt[N], tot, dep[N];
vector<long long> v[N];
void dfs1(int u, int fa) {
  mx[u] = 1;
  cnt[u] = cmx[u] = 0;
  for (auto k : v[u]) {
    if (k == fa) continue;
    dep[k] = dep[u] + 1;
    dfs1(k, u);
    if (mx[k] + 1 > mx[u])
      cmx[u] = mx[u], mx[u] = mx[k] + 1;
    else
      cmx[u] = max(cmx[u], mx[k] + 1);
    if (mx[k] + 1 >= tot) cnt[u]++;
  }
}
int rt;
void dfs2(int u, int fa) {
  if (cnt[u] + (f[u] >= tot) >= 3) rt = u;
  for (auto k : v[u]) {
    if (k == fa) continue;
    int t = (mx[k] + 1 == mx[u]) ? cmx[u] : mx[u];
    f[k] = max(f[u], t) + 1;
    dfs2(k, u);
  }
}
int fa[20][N], st[N], ed[N], opt, pos[N];
void dfs(int u) {
  dep[u] = dep[fa[0][u]] + 1;
  st[u] = ++opt;
  pos[u] = u;
  for (auto k : v[u]) {
    if (k == fa[0][u]) continue;
    fa[0][k] = u;
    dfs(k);
    if (dep[pos[k]] > dep[pos[u]]) pos[u] = pos[k];
  }
  ed[u] = opt;
}
int tiao(int x, int y) {
  for (int i = (int)(16); i >= (int)(0); i--)
    if (y >> i & 1) x = fa[i][x];
  return x;
}
bool check(int x, int y) { return st[x] <= st[y] && ed[x] >= ed[y]; }
int main() {
  int T = read();
  while (T--) {
    int n = read(), A = read(), B = read();
    for (int i = (int)(1); i <= (int)(n); i++) v[i].clear(), f[i] = 1;
    for (int i = (int)(1); i <= (int)(n - 1); i++) {
      int x = read(), y = read();
      v[x].push_back(y);
      v[y].push_back(x);
    }
    dep[A] = 1;
    dfs1(A, 0);
    tot = dep[B];
    dfs1(A, 0);
    rt = 0;
    dfs2(A, 0);
    if (!rt) {
      puts("NO");
      continue;
    }
    opt = dep[rt] = 0;
    fa[0][rt] = rt;
    dfs(rt);
    for (int i = (int)(1); i <= (int)(16); i++)
      for (int j = (int)(1); j <= (int)(n); j++)
        fa[i][j] = fa[i - 1][fa[i - 1][j]];
    bool d = 0;
    for (int o = (int)(1); o <= (int)(n); o++) {
      if (check(A, B) || check(B, A)) {
        d = 1;
        break;
      }
      int dis = dep[pos[A]] - dep[A];
      A = pos[A];
      B = tiao(B, dis);
      swap(A, B);
    }
    puts(d ? "YES" : "NO");
  }
}
