#include <bits/stdc++.h>
using namespace std;
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  os << '{';
  string sep;
  for (const auto &x : v) os << sep << x, sep = ", ";
  return os << '}';
}
template <typename T, size_t size>
ostream &operator<<(ostream &os, const array<T, size> &arr) {
  os << '{';
  string sep;
  for (const auto &x : arr) os << sep << x, sep = ", ";
  return os << '}';
}
template <typename A, typename B>
ostream &operator<<(ostream &os, const pair<A, B> &p) {
  return os << '(' << p.first << ", " << p.second << ')';
}
void dbg_out() { cerr << endl; }
template <typename Head, typename... Tail>
void dbg_out(Head H, Tail... T) {
  cerr << ' ' << H;
  dbg_out(T...);
}
template <typename T, bool maximum_mode = false>
struct RMQ {
  int n = 0;
  vector<T> values;
  vector<vector<int>> range_low;
  RMQ(const vector<T> &_values = {}) {
    if (!_values.empty()) build(_values);
  }
  static int largest_bit(int x) { return 31 - __builtin_clz(x); }
  int better_index(int a, int b) const {
    return (maximum_mode ? values[b] < values[a] : values[a] < values[b]) ? a
                                                                          : b;
  }
  void build(const vector<T> &_values) {
    values = _values;
    n = int(values.size());
    int levels = largest_bit(n) + 1;
    range_low.resize(levels);
    for (int k = 0; k < levels; k++) range_low[k].resize(n - (1 << k) + 1);
    for (int i = 0; i < n; i++) range_low[0][i] = i;
    for (int k = 1; k < levels; k++)
      for (int i = 0; i <= n - (1 << k); i++)
        range_low[k][i] = better_index(range_low[k - 1][i],
                                       range_low[k - 1][i + (1 << (k - 1))]);
  }
  int query_index(int a, int b) const {
    assert(0 <= a && a < b && b <= n);
    int level = largest_bit(b - a);
    return better_index(range_low[level][a],
                        range_low[level][b - (1 << level)]);
  }
  T query_value(int a, int b) const { return values[query_index(a, b)]; }
};
struct LCA {
  int n = 0;
  vector<vector<int>> adj;
  vector<int> parent, depth, subtree_size;
  vector<int> euler, first_occurrence;
  vector<int> tour_start, tour_end, tour_list, postorder;
  vector<int> heavy_root;
  RMQ<int> rmq;
  bool built;
  LCA(int _n = 0) { init(_n); }
  LCA(const vector<vector<int>> &_adj) { init(_adj); }
  void init(int _n) {
    n = _n;
    adj.assign(n, {});
    parent.resize(n);
    depth.resize(n);
    subtree_size.resize(n);
    first_occurrence.resize(n);
    tour_start.resize(n);
    tour_end.resize(n);
    tour_list.resize(n);
    postorder.resize(n);
    heavy_root.resize(n);
    built = false;
  }
  void init(const vector<vector<int>> &_adj) {
    init(int(_adj.size()));
    adj = _adj;
  }
  void add_edge(int a, int b) {
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  int degree(int v) const {
    return int(adj[v].size()) + (built && parent[v] >= 0);
  }
  void dfs(int node, int par) {
    parent[node] = par;
    depth[node] = par < 0 ? 0 : depth[par] + 1;
    subtree_size[node] = 1;
    adj[node].erase(remove(adj[node].begin(), adj[node].end(), par),
                    adj[node].end());
    for (int child : adj[node]) {
      dfs(child, node);
      subtree_size[node] += subtree_size[child];
    }
    sort(adj[node].begin(), adj[node].end(),
         [&](int a, int b) { return subtree_size[a] > subtree_size[b]; });
  }
  int tour, post_tour;
  void tour_dfs(int node, bool heavy) {
    heavy_root[node] = heavy ? heavy_root[parent[node]] : node;
    first_occurrence[node] = int(euler.size());
    euler.push_back(node);
    tour_list[tour] = node;
    tour_start[node] = tour++;
    bool heavy_child = true;
    for (int child : adj[node]) {
      tour_dfs(child, heavy_child);
      euler.push_back(node);
      heavy_child = false;
    }
    tour_end[node] = tour;
    postorder[node] = post_tour++;
  }
  void build(int root = -1) {
    parent.assign(n, -1);
    if (0 <= root && root < n) dfs(root, -1);
    for (int i = 0; i < n; i++)
      if (i != root && parent[i] < 0) dfs(i, -1);
    tour = post_tour = 0;
    euler.clear();
    euler.reserve(2 * n);
    for (int i = 0; i < n; i++)
      if (parent[i] < 0) {
        tour_dfs(i, false);
        euler.push_back(-1);
      }
    assert(int(euler.size()) == 2 * n);
    vector<int> euler_depths;
    euler_depths.reserve(euler.size());
    for (int node : euler)
      euler_depths.push_back(node < 0 ? node : depth[node]);
    rmq.build(euler_depths);
    built = true;
  }
  pair<int, int> find_farthest(int node, int par, int path) const {
    pair<int, int> current = {path, node};
    for (int neighbor : adj[node])
      if (neighbor != par)
        current = max(current, find_farthest(neighbor, node, path + 1));
    return current;
  }
  pair<int, pair<int, int>> get_diameter() const {
    int u = find_farthest(0, -1, 0).second;
    pair<int, int> farthest = find_farthest(u, -1, 0);
    int v = farthest.second;
    return {farthest.first, {u, v}};
  }
  int get_lca(int a, int b) const {
    a = first_occurrence[a];
    b = first_occurrence[b];
    if (a > b) swap(a, b);
    return euler[rmq.query_index(a, b + 1)];
  }
  bool is_ancestor(int a, int b) const {
    return tour_start[a] <= tour_start[b] && tour_start[b] < tour_end[a];
  }
  bool on_path(int x, int a, int b) const {
    return (is_ancestor(x, a) || is_ancestor(x, b)) &&
           is_ancestor(get_lca(a, b), x);
  }
  int get_dist(int a, int b) const {
    return depth[a] + depth[b] - 2 * depth[get_lca(a, b)];
  }
  int child_ancestor(int a, int b) const {
    assert(a != b);
    assert(is_ancestor(a, b));
    int child =
        euler[rmq.query_index(first_occurrence[a], first_occurrence[b] + 1) +
              1];
    assert(parent[child] == a);
    assert(is_ancestor(child, b));
    return child;
  }
  int get_kth_ancestor(int a, int k) const {
    while (a >= 0) {
      int root = heavy_root[a];
      if (depth[root] <= depth[a] - k) return tour_list[tour_start[a] - k];
      k -= depth[a] - depth[root] + 1;
      a = parent[root];
    }
    return a;
  }
  int get_kth_node_on_path(int a, int b, int k) const {
    int anc = get_lca(a, b);
    int first_half = depth[a] - depth[anc];
    int second_half = depth[b] - depth[anc];
    assert(0 <= k && k <= first_half + second_half);
    if (k < first_half)
      return get_kth_ancestor(a, k);
    else
      return get_kth_ancestor(b, first_half + second_half - k);
  }
  int get_common_node(int a, int b, int c) const {
    int x = get_lca(a, b);
    int y = get_lca(b, c);
    int z = get_lca(c, a);
    if (depth[y] > depth[x]) x = y;
    if (depth[z] > depth[x]) x = z;
    return x;
  }
  vector<pair<int, int>> compress_tree(vector<int> nodes) const {
    if (nodes.empty()) return {};
    auto &&compare_tour = [&](int a, int b) {
      return tour_start[a] < tour_start[b];
    };
    sort(nodes.begin(), nodes.end(), compare_tour);
    int k = int(nodes.size());
    for (int i = 0; i < k - 1; i++)
      nodes.push_back(get_lca(nodes[i], nodes[i + 1]));
    sort(nodes.begin() + k, nodes.end(), compare_tour);
    inplace_merge(nodes.begin(), nodes.begin() + k, nodes.end(), compare_tour);
    nodes.erase(unique(nodes.begin(), nodes.end()), nodes.end());
    vector<pair<int, int>> result = {{nodes[0], -1}};
    for (int i = 1; i < int(nodes.size()); i++)
      result.emplace_back(nodes[i], get_lca(nodes[i], nodes[i - 1]));
    return result;
  }
};
template <typename T>
void output_vector(const vector<T> &v, bool add_one = false, int start = -1,
                   int end = -1) {
  if (start < 0) start = 0;
  if (end < 0) end = int(v.size());
  for (int i = start; i < end; i++)
    cout << v[i] + (add_one ? 1 : 0) << (i < end - 1 ? ' ' : '\n');
}
int N, A[2], P;
LCA lca;
vector<bool> on_path;
vector<array<int, 2>> deepest;
vector<array<array<bool, 2>, 2>> visited;
bool deeper(int x, int y) {
  if (x < 0) return false;
  if (y < 0) return true;
  return lca.depth[x] > lca.depth[y];
}
void deepest_dfs(int node) {
  deepest[node] = {-1, -1};
  if (!on_path[node] && lca.adj[node].empty()) deepest[node][0] = node;
  for (int child : lca.adj[node]) {
    deepest_dfs(child);
    if (!on_path[child]) {
      array<int, 3> choices = {deepest[node][0], deepest[node][1],
                               deepest[child][0]};
      sort(choices.begin(), choices.end(), deeper);
      deepest[node] = {choices[0], choices[1]};
    }
  }
}
bool answer;
void solve(int node, int which, int toward) {
  ;
  if (visited[node][which][toward]) return;
  visited[node][which][toward] = true;
  if (which == 0 && node == A[1] && toward == 0) {
    answer = true;
    return;
  }
  if (which == 1 && node == A[0] && toward == 1) {
    answer = true;
    return;
  }
  int toward_node = A[toward];
  assert(!on_path[node] || node == A[0] || node == A[1]);
  assert(lca.get_dist(node, toward_node) >= P);
  int other_node = lca.get_kth_node_on_path(node, toward_node, P);
  {
    int toward_node_2 = A[!toward];
    if (lca.get_dist(node, toward_node_2) >= P &&
        lca.get_kth_node_on_path(node, toward_node_2, P) == other_node)
      solve(node, which, !toward);
  };
  for (int child : lca.adj[node])
    if (!on_path[child]) {
      ;
      solve(child, which, toward);
    }
  if (!on_path[node] && other_node != toward_node) {
    ;
    solve(lca.parent[node], which, toward);
  }
  for (int i = 0; i < 2; i++) {
    int option = deepest[other_node][i];
    if (option >= 0 && lca.on_path(other_node, node, option)) {
      int goes = lca.get_kth_node_on_path(node, option,
                                          lca.get_dist(other_node, option));
      if (on_path[goes] || lca.is_ancestor(goes, option)) {
        ;
        solve(option, !which, !toward);
      }
    }
  }
}
void run_case() {
  cin >> N >> A[0] >> A[1];
  A[0]--;
  A[1]--;
  lca.init(N);
  for (int i = 0; i < N - 1; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    lca.add_edge(u, v);
  }
  lca.build(A[0]);
  P = lca.get_dist(A[0], A[1]);
  on_path.resize(N);
  for (int i = 0; i < N; i++) on_path[i] = lca.on_path(i, A[0], A[1]);
  deepest.assign(N, {-1, -1});
  deepest_dfs(A[0]);
  visited.assign(N,
                 {array<bool, 2>{false, false}, array<bool, 2>{false, false}});
  answer = false;
  solve(A[0], 0, 1);
  solve(A[1], 1, 0);
  cout << (answer ? "YES" : "NO") << '\n';
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int tests;
  cin >> tests;
  while (tests-- > 0) run_case();
}
