#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 14;
int n, a, b, up[maxn], par[maxn];
struct KeepFirstThreeBest {
  int a = 0, b = 0, c = 0, cer;
  void add(int val, int ce) {
    if (val > a)
      c = b, b = a, a = val, cer = ce;
    else if (val > b)
      c = b, b = val;
    else
      c = max(c, val);
  }
  int get(int w = -1) { return cer == w ? b : a; }
} dn[maxn];
vector<int> g[maxn];
void dfs(int v) {
  for (auto u : g[v])
    if (u != par[v]) {
      par[u] = v;
      dfs(u);
      dn[v].add(dn[u].get() + 1, u);
    }
}
void dfs_up(int v) {
  for (auto u : g[v])
    if (u != par[v]) {
      up[u] = max(up[v], dn[v].get(u)) + 1;
      dfs_up(u);
    }
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    cin >> n >> a >> b;
    a--, b--;
    fill(g, g + n, vector<int>());
    fill(dn, dn + n, KeepFirstThreeBest());
    for (int i = 0; i < n - 1; i++) {
      int v, u;
      cin >> v >> u;
      v--, u--;
      g[v].push_back(u);
      g[u].push_back(v);
    }
    par[a] = -1;
    up[a] = 0;
    dfs(a);
    dfs_up(a);
    deque<int> path;
    for (int v = b; v != -1; v = par[v]) path.push_front(v);
    int reml = 0, remr = 0, snake_len = path.size() - 1;
    while (path.size() > 1) {
      auto cp = path;
      while (path.size() > 1 && remr + 1 < up[path[1]] - reml) {
        remr++;
        path.pop_back();
      }
      while (path.size() > 1 && reml < dn[path.back()].get() - remr) {
        reml++;
        path.pop_front();
      }
      if (cp == path) break;
    }
    bool good_ver = false;
    for (int i = 0; i < n; i++)
      good_ver |=
          up[i] >= snake_len && dn[i].b >= snake_len || dn[i].c >= snake_len;
    cout << (path.size() <= 1 && good_ver ? "YES\n" : "NO\n");
  }
}
