#include <bits/stdc++.h>
using namespace std;
inline int qr() {
  int f = 0, fu = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') fu = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    f = (f << 3) + (f << 1) + c - 48;
    c = getchar();
  }
  return f * fu;
}
const int N = 1e5 + 10;
int head[N], ver[N << 1], Next[N << 1], tot;
int n, a, b, T, d[N], f[N][3], len;
vector<int> seq, stl, str;
inline void add(int x, int y) {
  ver[++tot] = y;
  Next[tot] = head[x];
  head[x] = tot;
}
inline void init() {
  memset(head, 0, sizeof(int) * (n + 1));
  for (int i = 1; i <= n; ++i)
    for (int j = 0; j <= 2; ++j) f[i][j] = 0;
  tot = 0, seq.clear(), stl.clear(), str.clear();
}
inline void addv(int x, int v) {
  int pos = -1;
  for (int i = 0; i <= 2; ++i)
    if (v >= f[x][i]) {
      pos = i;
      break;
    }
  if (pos == -1) return;
  for (int i = 2; i >= pos + 1; --i) f[x][i] = f[x][i - 1];
  f[x][pos] = v;
}
void dfs1(int x, int fa, int dep) {
  d[x] = 0;
  if (x == b) len = dep;
  for (int i = head[x]; i; i = Next[i]) {
    int y = ver[i];
    if (y == fa) continue;
    dfs1(y, x, dep + 1);
    addv(x, d[y] + 1);
    d[x] = max(d[x], d[y] + 1);
  }
}
bool dfs2(int x, int fa) {
  if (f[x][2] >= len) return true;
  for (int i = head[x]; i; i = Next[i]) {
    int y = ver[i];
    if (y == fa) continue;
    addv(y, f[x][d[y] + 1 == f[x][0]] + 1);
    if (dfs2(y, x)) return true;
  }
  return false;
}
bool dfs3(int x, int fa) {
  bool flag = (x == b);
  d[x] = 0;
  for (int i = head[x]; i; i = Next[i]) {
    int y = ver[i];
    if (y == fa) continue;
    if (dfs3(y, x))
      flag = true;
    else
      d[x] = max(d[x], d[y] + 1);
  }
  if (flag) seq.push_back(x);
  return flag;
}
int main() {
  T = qr();
  while (T--) {
    n = qr(), a = qr(), b = qr();
    init();
    for (int i = 1; i <= n - 1; ++i) {
      int x = qr(), y = qr();
      add(x, y), add(y, x);
    }
    dfs1(a, 0, 0);
    if (!dfs2(a, 0)) {
      puts("NO");
      continue;
    }
    dfs3(a, 0);
    for (int i = 0; i <= len; ++i) {
      stl.push_back(stl.empty() || d[seq[i]] - i > stl.back() ? d[seq[i]] - i
                                                              : stl.back());
      str.push_back(str.empty() || d[seq[len - i]] - i > str.back()
                        ? d[seq[len - i]] - i
                        : str.back());
    }
    reverse(str.begin(), str.end());
    int l = 0, r = len;
    while (l < r) {
      if (l < str[r])
        l = str[r];
      else if (len - r < stl[l])
        r = len - stl[l];
      else
        break;
    }
    puts(l >= r ? "YES" : "NO");
  }
  return 0;
}
