#include <bits/stdc++.h>

using ll = long long;

void solveTest() {
    int n;
    std::cin >> n;
    std::vector<std::pair<std::string, std::string>> names(n);
    for (auto& [x, y] : names) {
        std::cin >> x >> y;
    }
    std::set<std::string> byFirst, bySecond;
    for (int i = n - 1; i > 0; --i) {
        auto[x, y] = names[i];
        auto[px, py] = names[i - 1];

        if (x != px && y != py && (byFirst.count(px) || bySecond.count(py))) {
            std::cout << "No\n";
            return;
        }

        byFirst.insert(x);
        bySecond.insert(y);
    }

    std::cout << "Yes\n";
}

int main() {
    int t;
    std::cin >> t;
    while (t--) {
        solveTest();
    }
    
    return 0;
}
