/**
 *    author:  tourist
 *    created: 05.11.2025 18:16:53
**/
#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(...) 42
#endif

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int tt;
  cin >> tt;
  while (tt--) {
    int n;
    cin >> n;
    vector<string> a(n), b(n);
    for (int i = 0; i < n; i++) {
      cin >> a[i] >> b[i];
    }
    bool ok = true;
    set<string> sa, sb;
    for (int i = n - 1; i >= 1; i--) {
      if (a[i] != a[i - 1] && b[i] != b[i - 1]) {
        if (sa.find(a[i - 1]) != sa.end() || sb.find(b[i - 1]) != sb.end()) {
          ok = false;
          break;
        }
      }
      sa.insert(a[i]);
      sb.insert(b[i]);
    }
    cout << (ok ? "Yes" : "No") << '\n';
  }
  return 0;
}
