#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 1;
const int L = 18;
vector<int> adj[N];
int time_out[N], time_in[N], timer;
int dep[N], low[N], par[L][N];
int chd[N][3], height[N];
int root;
int len;
int dfs(int u, int p, int v) {
  if (u == v) return 0;
  int dist = N;
  for (int c : adj[u]) {
    if (c != p) {
      dist = min(dist, dfs(c, u, v) + 1);
    }
  }
  return dist;
}
void update(int u, int c) {
  for (int i = 0; i < 3; ++i) {
    if (height[c] > chd[u][i]) {
      for (int j = 2; j > i; --j) {
        chd[u][j] = chd[u][j - 1];
      }
      chd[u][i] = height[c];
      return;
    }
  }
}
void dfs_pull(int u, int p) {
  for (int c : adj[u]) {
    if (c != p) {
      dfs_pull(c, u);
      update(u, c);
    }
  }
  height[u] = chd[u][0] + 1;
}
void dfs_push(int u, int p) {
  update(u, p);
  for (int c : adj[u]) {
    if (c != p) {
      if (chd[u][0] == height[c]) {
        height[u] = chd[u][1] + 1;
      }
      dfs_push(c, u);
      height[u] = max(height[u], chd[u][0] + 1);
    }
  }
  if (chd[u][2] >= len) {
    root = u;
  }
}
void dfs_low(int u, int p) {
  time_in[u] = ++timer;
  par[0][u] = p;
  low[u] = u;
  for (int c : adj[u]) {
    if (c != p) {
      dep[c] = dep[u] + 1;
      dfs_low(c, u);
      if (dep[low[c]] > dep[low[u]]) {
        low[u] = low[c];
      }
    }
  }
  time_out[u] = timer;
}
bool is_ancestor(int u, int v) {
  return time_in[u] <= time_in[v] && time_out[u] >= time_out[v];
}
void solve() {
  int n, a, b;
  cin >> n >> a >> b;
  fill(adj + 1, adj + n + 1, vector<int>());
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j < 3; ++j) {
      chd[i][j] = 0;
    }
  }
  for (int i = 0; i < n - 1; ++i) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  root = 0;
  len = dfs(a, 0, b);
  dfs_pull(1, 0);
  dfs_push(1, 0);
  if (root == 0) {
    cout << "NO\n";
    return;
  }
  timer = 0;
  dep[root] = 0;
  par[0][root] = 0;
  dfs_low(root, 0);
  time_out[0] = timer;
  if (dep[a] > dep[b]) {
    swap(a, b);
  }
  int log_n = 1;
  for (; (1 << log_n) < 2 * n; ++log_n) {
    for (int i = 1; i <= n; ++i) {
      par[log_n][i] = par[log_n - 1][par[log_n - 1][i]];
    }
  }
  bool ok = is_ancestor(a, b);
  for (int k = 0; k < n && !ok; ++k) {
    int delta = dep[low[a]] - dep[a];
    for (int i = log_n - 1; i >= 0; --i) {
      if ((1 << i) <= delta) {
        delta -= 1 << i;
        b = par[i][b];
      }
    }
    a = low[a];
    swap(a, b);
    ok |= is_ancestor(a, b);
  }
  cout << (ok ? "YES" : "NO") << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
}
