#include <bits/stdc++.h>
using namespace std;

void solve(){
	int N;
	cin >> N;
	vector<pair<string, string> > names;
	for(int i = 0; i < N; i++){
		string a, b;
		cin >> a >> b;
		names.push_back({a, b});
	}
	map<string, int> freq1;
	map<string, int> freq2;
	for(int i = 0; i < N; i++){
		freq1[names[i].first]++;
		freq2[names[i].second]++;
	}
	bool ok = true;
	for(int i = 0; i < N; i++){
		if(i > 0){
			if(names[i].first != names[i-1].first && names[i].second != names[i-1].second){
				int nsimilar = freq1[names[i-1].first] + freq2[names[i-1].second];
				if(nsimilar > 0){
					ok = false;
				}
			}
		}
		freq1[names[i].first]--;
		freq2[names[i].second]--;
	}
	cout << (ok ? "Yes" : "No") << '\n';
}

int main(){
	ios_base::sync_with_stdio(false), cin.tie(nullptr);
	int T;
	cin >> T;
	while(T--) solve();
}
