#include <bits/stdc++.h>

using namespace std;
using ll = long long;
// #define int long long
using ld = long double;

#define all(v) (v).begin(), (v).end()
#define db(x) cerr << #x << " = " << x << '\n'
#define mp make_pair
#define eb emplace_back
#define pb push_back
#define sz(v) (int)((v).size())
#define pw(x) (1LL << (int)(x))
#define fr(i, a, b) for (int i = (a); i <= (b); ++i)
#define rf(i, a, b) for (int i = (a); i >= (b); --i)
#define fe(x, y) for (auto &x: y)
#define fi first
#define se second

mt19937_64 rng(566);

ll rnd(ll l, ll r) {
    return rng() % (r - l + 1) + l;
}

template<typename T>
bool umn(T &a, T b) {
    return a > b ? a = b, 1 : 0;
}

template<typename T>
bool umx(T &a, T b) {
    return a < b ? a = b, 1 : 0;
}

template<typename T>
using ve = vector<T>;

using pii = pair<int, int>;
using pll = pair<ll, ll>;

const double eps = 1e-8;
const ll mod = 1e9 + 8;
const int inf0 = 1e9 + 10;
const ll inf = 2e18 + 10;

void solve();

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#ifdef LC
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int t = 1;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

int n;
ve<array<string, 2>> a;
map<string, int> withFirst, withSecond;

void solve() {
    cin >> n;
    a.resize(n);
    withFirst.clear();
    withSecond.clear();
    fr (i, 0, n - 1) {
        cin >> a[i][0] >> a[i][1];
        withFirst[a[i][0]]++;
        withSecond[a[i][1]]++;
    }

    fr (i, 0, n - 1) {
        if (i > 0) {
            bool b = a[i][0] == a[i - 1][0] || a[i][1] == a[i - 1][1];
            if (b == false && (withFirst[a[i - 1][0]] || withSecond[a[i - 1][1]])) {
                cout << "No\n";
                return;
            }
        }
        withFirst[a[i][0]]--;
        withSecond[a[i][1]]--;
    }
    cout << "Yes\n";
}
