#include <bits/stdc++.h>
using namespace std;
const int logn = 19;
class testcase {
  int n, a, b, pv;
  vector<vector<int> > g;
  vector<int> d, deepest, my_subtree, p;
  void dfs1(int v, int p = -1) {
    for (int i : g[v]) {
      if (i == p) continue;
      d[i] = d[v] + 1;
      dfs1(i, v);
      deepest[v] = max(deepest[v], deepest[i] + 1);
    }
  }
  void dfs2(int v, int p = -1, int dist = 0) {
    vector<int> d3(3, 0);
    d3[0] = dist;
    for (int i : g[v]) {
      if (i == p) continue;
      d3.push_back(deepest[i] + 1);
      sort(d3.begin(), d3.end(), greater<int>());
      d3.pop_back();
    }
    pv = max(pv, d3[2]);
    for (int i : g[v])
      if (i != p)
        dfs2(i, v,
             max(dist + 1, ((deepest[i] + 1 == d3[0] ? d3[1] : d3[0]) + 1)));
  }
  bool dfs3(int v) {
    bool bad = v == b;
    for (int i : g[v]) {
      if (i == p[v]) continue;
      p[i] = v;
      if (dfs3(i))
        bad = true;
      else
        my_subtree[v] = max(my_subtree[v], my_subtree[i] + 1);
    }
    return bad;
  }

 public:
  bool solve() {
    cin >> n >> a >> b;
    a--;
    b--;
    g.resize(n);
    d.assign(n, 0);
    deepest.assign(n, 0);
    my_subtree.assign(n, 0);
    pv = -1;
    p.assign(n, -1);
    for (int i = 0, u, v; i < n - 1; i++) {
      cin >> u >> v;
      g[--u].push_back(--v);
      g[v].push_back(u);
    }
    dfs1(a);
    dfs2(a);
    if (d[b] > pv) return false;
    dfs3(a);
    vector<int> v;
    for (int i = b; i != -1; i = p[i]) v.push_back(my_subtree[i]);
    int len = v.size();
    int head = 0, tail = len - 1;
    int best_tail = tail - v[head], best_head = v[tail];
    while (head < tail) {
      if (head < best_head) {
        head++;
        best_tail = min(best_tail, head + (len - 1 - v[head]));
      } else if (tail > best_tail) {
        tail--;
        best_head = max(best_head, tail - (len - 1 - v[tail]));
      } else
        break;
    }
    return head == tail;
  }
};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    testcase tc;
    cout << (tc.solve() ? "YES\n" : "NO\n");
  }
  return 0;
}
