#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
using namespace std;
long long MOD = 1e9 + 7;
double eps = 1e-12;
long long mpow(long long a, long long b) {
  if (a == 0) return 0;
  if (b == 0) return 1;
  long long t1 = mpow(a, b / 2);
  t1 *= t1;
  t1 %= MOD;
  if (b % 2) t1 *= a;
  t1 %= MOD;
  return t1;
}
long long mpow(long long a, long long b, long long p) {
  if (a == 0) return 0;
  if (b == 0) return 1;
  long long t1 = mpow(a, b / 2, p);
  t1 *= t1;
  t1 %= p;
  if (b % 2) t1 *= a;
  t1 %= p;
  return t1;
}
long long modinverse(long long a, long long m) {
  long long m0 = m;
  long long y = 0, x = 1;
  if (m == 1) return 0;
  while (a > 1) {
    long long q = a / m;
    long long t = m;
    m = a % m, a = t;
    t = y;
    y = x - q * y;
    x = t;
  }
  if (x < 0) x += m0;
  return x;
}
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());
long long range(long long l, long long r) { return l + mt() % (r - l + 1); }
long long rev(long long v) { return mpow(v, MOD - 2); }
vector<vector<long long> > gr, dep;
vector<long long> p, vis;
void dfs1(long long v, long long pr) {
  p[v] = pr;
  for (auto it : gr[v])
    if (it != pr) {
      dfs1(it, v);
      dep[v].push_back(dep[it][0] + 1);
      sort((dep[v]).begin(), (dep[v]).end(), greater<long long>());
      if (((long long)(dep[v]).size()) > 3) {
        dep[v].pop_back();
      }
    }
}
void dfs2(long long v, long long pr) {
  for (auto it : gr[v])
    if (it != pr) {
      dep[it].push_back(
          ((dep[v][0] == dep[it][0] + 1) ? dep[v][1] : dep[v][0]) + 1);
      sort((dep[it]).begin(), (dep[it]).end(), greater<long long>());
      if (((long long)(dep[it]).size()) > 3) {
        dep[it].pop_back();
      }
      dfs2(it, v);
    }
}
long long dfs3(long long v) {
  long long ret = 0;
  vis[v] = 1;
  for (auto it : gr[v])
    if (!vis[it]) {
      ret = max(ret, dfs3(it) + 1);
    }
  return ret;
}
void my_clear() {
  gr.clear();
  dep.clear();
  p.clear();
  vis.clear();
}
void solve() {
  long long n, a, b;
  cin >> n >> a >> b;
  gr.resize(n);
  p.resize(n);
  dep.resize(n, vector<long long>(3, 0));
  vis.resize(n, 0);
  a--, b--;
  for (long long i = 0; i < n - 1; i++) {
    long long u, v;
    cin >> u >> v;
    u--, v--;
    gr[u].push_back(v);
    gr[v].push_back(u);
  }
  dfs1(a, -1);
  dfs2(a, -1);
  vector<long long> path;
  for (long long v = b; v != -1; v = p[v]) {
    vis[v] = 1;
  }
  for (long long v = b; v != -1; v = p[v]) {
    path.push_back(dfs3(v));
  }
  long long bo = 0;
  for (long long i = 0; i < n; i++) {
    if (dep[i][2] >= ((long long)(path).size()) - 1) bo = 1;
  }
  if (!bo) {
    cout << "NO"
         << "\n";
    my_clear();
    return;
  }
  long long l = 0, r = ((long long)(path).size()) - 1, L = path[r],
            R = ((long long)(path).size()) - 1 - path[l];
  while (l < r) {
    if (L > l) {
      l++;
      R = min(R, ((long long)(path).size()) - 1 - path[l] + l);
    } else if (R < r) {
      r--;
      L = max(L, path[r] - (((long long)(path).size()) - 1 - r));
    } else {
      break;
    }
  }
  cout << ((l == r) ? "YES" : "NO") << "\n";
  my_clear();
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t = 1;
  cin >> t;
  for (long long i = 0; i < t; i++) {
    solve();
  }
  return 0;
}
