#include <bits/stdc++.h>
using namespace std;
namespace std {
string to_string(char c) { return string(1, c); }
string to_string(bool b) { return b ? "true" : "false"; }
string to_string(const char* str) { return string(str); }
string to_string(const string& str) { return str; }
template <class F, class S>
string to_string(const pair<F, S>& p) {
  return string("(") + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <class T>
string to_string(const T& vec) {
  string str = "[";
  bool first = true;
  for (const auto& x : vec) {
    if (!first) str += ", ";
    first = false;
    str += to_string(x);
  }
  str += "]";
  return str;
}
void dbg_print() { cerr << " }" << endl; }
template <class H, class... T>
void dbg_print(H head, T... tail) {
  cerr << to_string(head);
  if (sizeof...(tail)) cerr << ", ";
  dbg_print(tail...);
}
}  // namespace std
constexpr int mxn = 1e5;
int n, a, b, max_child[mxn][3], max_parent[mxn];
bool can_turn[mxn];
vector<int> adj[mxn], body;
int dfs1(int u, int p = -1) {
  if (~p && (int)adj[u].size() < 2) return max_child[u][0] = 1;
  for (int v : adj[u])
    if (v != p) {
      int len = dfs1(v, u) + 1;
      if (len > max_child[u][0]) {
        max_child[u][2] = max_child[u][1];
        max_child[u][1] = max_child[u][0];
        max_child[u][0] = len;
      } else if (len > max_child[u][1]) {
        max_child[u][2] = max_child[u][1];
        max_child[u][1] = len;
      } else if (len > max_child[u][2]) {
        max_child[u][2] = len;
      }
    }
  return max_child[u][0];
}
bool dfs2(int u, int p = -1, int mxp = 0) {
  max_parent[u] = mxp + 1;
  int max_ch = -1, len[2] = {-2, -3};
  for (int v : adj[u])
    if (v != p) {
      if (max_child[v][0] + 1 > len[0]) {
        len[1] = len[0];
        len[0] = max_child[v][0] + 1;
        max_ch = v;
      } else if (max_child[v][0] + 1 > len[1]) {
        len[1] = max_child[v][0] + 1;
      }
    }
  bool is_body = (u == b);
  for (int v : adj[u])
    if (v != p) is_body |= dfs2(v, u, max(max_parent[u], len[(v == max_ch)]));
  if (is_body) body.push_back(u);
  return is_body;
}
pair<int, bool> dfs3(int u, int p) {
  if ((int)adj[u].size() < 2) return make_pair(1, can_turn[u]);
  int mx = 0, ok = can_turn[u];
  for (int v : adj[u])
    if (v != p) {
      pair<int, bool> pr = dfs3(v, u);
      mx = max(mx, pr.first);
      ok |= pr.second;
    }
  return make_pair(mx + 1, ok);
}
void solve() {
  cin >> n >> a >> b;
  --a, --b;
  body.clear();
  memset(can_turn, 0, n);
  memset(max_child, -1, 12 * n);
  memset(max_parent, -1, 4 * n);
  for (int i = 0; i < n; i++) adj[i].clear();
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v, --u, --v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  dfs1(a);
  dfs2(a);
  int body_length = body.size();
  bool ok_3 = false;
  for (int i = 0; i < n; i++) {
    int cnt = (int)(max_parent[i] >= body_length);
    cnt += (int)(max_child[i][0] >= body_length);
    cnt += (int)(max_child[i][1] >= body_length);
    cnt += (int)(max_child[i][2] >= body_length);
    if (cnt >= 3) {
      can_turn[i] = true;
      ok_3 = true;
    }
  }
  if (!ok_3) {
    cout << "NO\n";
    return;
  }
  vector<int> subtree(body_length);
  for (int i = 0; i < body_length; i++) {
    int pre = i > 0 ? body[i - 1] : -1;
    int nxt = i + 1 < body_length ? body[i + 1] : -1;
    for (int v : adj[body[i]]) {
      if (v == pre || v == nxt) continue;
      auto [len, has_turn] = dfs3(v, body[i]);
      subtree[i] = max(subtree[i], len);
      can_turn[body[i]] |= has_turn;
    }
  };
  int l = 0, r = body_length - 1;
  int lmax = subtree[r], rmin = r - subtree[l];
  bool ok = can_turn[body[l]] || can_turn[body[r]];
  while ((l < lmax || rmin < r) && !ok) {
    if (l < lmax) l++, rmin = min(rmin, l + (body_length - 1 - subtree[l]));
    if (rmin < r) r--, lmax = max(lmax, r - (body_length - 1 - subtree[r]));
    if (can_turn[body[l]] || can_turn[body[r]]) ok = true;
  }
  cout << (ok ? "YES\n" : "NO\n");
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int tt = 1;
  cin >> tt;
  while (tt--) solve();
  return 0;
}
