#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O2,no-stack-protector,unroll-loops,fast-math")
const long long maxn = 1e5 + 10, maxm = 1e6 + 10, lg = 17, mod = 998244353,
                inf = 1e18;
long long n, len, a, b, par[maxn][lg + 1], h[maxn], zuz[maxn], tguz;
pair<long long, long long> mx[maxn][4];
vector<long long> g[maxn];
bool kor[maxn];
void dfd(long long v = 1, long long p = 0) {
  h[v] = h[p] + 1;
  par[v][0] = p;
  for (int i = 1; i <= lg; i++) par[v][i] = par[par[v][i - 1]][i - 1];
  fill(mx[v], mx[v] + 4, make_pair(0, v));
  for (auto u : g[v])
    if (u != p) {
      dfd(u, v);
      mx[v][0] = mx[u][3];
      mx[v][0].first++;
      sort(mx[v], mx[v] + 4);
    }
}
void dfu(long long v = 1, long long p = 0) {
  if (mx[v][1].first >= len) zuz[v]++, tguz++;
  for (auto u : g[v])
    if (u != p) {
      mx[u][0] = (mx[v][3].second == mx[u][3].second ? mx[v][2] : mx[v][3]);
      mx[u][0].first++;
      sort(mx[u], mx[u] + 4);
      dfu(u, v);
      zuz[v] += zuz[u];
    }
}
long long gup(long long v, long long x) {
  for (int i = 0; i <= lg; i++)
    if (x >> i & 1) v = par[v][i];
  return v;
}
long long lca(long long v, long long u) {
  if (h[v] < h[u]) swap(v, u);
  v = gup(v, h[v] - h[u]);
  if (v == u) return v;
  for (int i = lg; i >= 0; i--)
    if (par[v][i] != par[u][i]) v = par[v][i], u = par[u][i];
  return par[v][0];
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  long long T;
  cin >> T;
  while (T--) {
    cin >> n >> a >> b;
    for (int i = 1; i < n; i++) {
      long long v, u;
      cin >> v >> u;
      g[v].push_back(u), g[u].push_back(v);
    }
    dfd();
    len = h[a] + h[b] - 2 * h[lca(a, b)];
    dfu();
    while (1) {
      long long ms;
      for (int i : {3, 2, 1, 0}) {
        long long na = mx[a][i].second;
        if (h[b] + h[na] - 2 * h[lca(b, na)] == len + mx[a][i].first) {
          ms = mx[a][i].first;
          a = na;
          break;
        }
      }
      long long o = lca(a, b);
      if (h[b] - h[o] >= ms)
        b = gup(b, ms);
      else {
        ms -= h[b] - h[o];
        b = gup(a, h[a] - (h[o] + ms));
      }
      if (kor[a]) {
        cout << "NO\n";
        break;
      }
      o = lca(a, b);
      if (o == b) {
        if (zuz[gup(a, h[a] - h[b] - 1)] < tguz) {
          cout << "YES\n";
          break;
        }
      } else if (zuz[b]) {
        cout << "YES\n";
        break;
      }
      kor[a] = 1;
      swap(a, b);
    }
    for (int i = 1; i <= n; i++) {
      g[i].clear(), kor[i] = 0, h[i] = 0, zuz[i] = 0;
      memset(par[i], 0, sizeof(par[i]));
    }
    tguz = 0;
  }
  return 0;
}
