#include <bits/stdc++.h>
using namespace std;
inline void read(int &x) {
  int v = 0, f = 1;
  char c = getchar();
  while (!isdigit(c) && c != '-') c = getchar();
  if (c == '-')
    f = -1;
  else
    v = (c & 15);
  while (isdigit(c = getchar())) v = (v << 1) + (v << 3) + (c & 15);
  x = v * f;
}
inline void read(long long &x) {
  long long v = 0ll, f = 1ll;
  char c = getchar();
  while (!isdigit(c) && c != '-') c = getchar();
  if (c == '-')
    f = -1;
  else
    v = (c & 15);
  while (isdigit(c = getchar())) v = (v << 1) + (v << 3) + (c & 15);
  x = v * f;
}
inline void readc(char &x) {
  char c;
  while (((c = getchar()) == ' ') || c == '\n')
    ;
  x = c;
}
int t, n, a, b, m, i, j, dep[200005], hgt[200005], hv;
vector<int> e[200005], vs[200005], seq;
void dfs1(int x, int fa) {
  vs[x].resize(3);
  hgt[x] = 0;
  for (__typeof((e[x]).begin()) it = (e[x]).begin(); it != (e[x]).end(); it++) {
    if (*it == fa) continue;
    dep[*it] = dep[x] + 1;
    dfs1(*it, x);
    hgt[x] = max(hgt[x], hgt[*it] + 1);
    vs[x].push_back(hgt[*it] + 1);
  }
}
void dfs2(int x, int fa) {
  sort(vs[x].begin(), vs[x].end(), greater<int>());
  for (__typeof((e[x]).begin()) it = (e[x]).begin(); it != (e[x]).end(); it++) {
    if (*it == fa) continue;
    vs[*it].push_back(1 + vs[x][hgt[*it] + 1 == vs[x][0]]);
    dfs2(*it, x);
  }
}
bool dfs3(int x, int fa) {
  bool in_line = 0;
  hgt[x] = 0;
  if (x == b) in_line = 1;
  for (__typeof((e[x]).begin()) it = (e[x]).begin(); it != (e[x]).end(); it++) {
    if (*it == fa) continue;
    if (dfs3(*it, x))
      in_line = 1;
    else
      hgt[x] = max(hgt[x], hgt[*it] + 1);
  }
  if (in_line) {
    seq.push_back(hgt[x]);
  }
  return in_line;
}
int main() {
  read(t);
  while (t--) {
    read(n);
    read(a);
    read(b);
    for (((i)) = (1); ((i)) <= ((n)); ((i))++) e[i].clear();
    for (((i)) = (1); ((i)) <= ((n)); ((i))++) hgt[i] = 0;
    for (((i)) = (1); ((i)) <= ((n)); ((i))++) vs[i].clear();
    for (((i)) = (1); ((i)) <= ((n - 1)); ((i))++) {
      int x, y;
      read(x);
      read(y);
      e[x].push_back(y);
      e[y].push_back(x);
    }
    dep[a] = 0;
    dfs1(a, 0);
    dfs2(a, 0);
    hv = 0;
    for (((i)) = (1); ((i)) <= ((n)); ((i))++) {
      if (vs[i][2] >= dep[b]) {
        hv = 1;
      }
    }
    if (!hv) {
      puts("NO");
      continue;
    }
    seq.clear();
    dfs3(a, 0);
    int l = 0, r = seq.size() - 1;
    int sl = seq[r], sr = r - seq[l];
    while (l < r) {
      if (l < sl) {
        l++;
        sr = min(sr, (int)seq.size() - 1 - (seq[l] - l));
      } else if (r > sr) {
        r--;
        sl = max(sl, seq[r] - ((int)seq.size() - 1 - r));
      } else
        break;
    }
    if (l == r) {
      puts("YES");
    } else
      puts("NO");
  }
  return 0;
}
