///////////////////////////////    _LeMur_
#define _CRT_SECURE_NO_WARNINGS
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <complex>
#include <cassert>
#include <cfloat>
#include <memory>
#include <chrono>
#include <random>
#include <climits>
#include <limits>
#include <bitset>
#include <cstdio>
#include <vector>
#include <string>
#include <stack>
#include <tuple>
#include <queue>
#include <ctime>
#include <cmath>
#include <list>
#include <map>
#include <set>

using namespace std;

const int N = 100005;
const int inf = 1000 * 1000 * 1000;
const int mod = 1000 * 1000 * 1000 + 7;
// mt19937 myrand(chrono::steady_clock::now().time_since_epoch().count());
mt19937 myrand(373);

int t;
int n;
string s1[N], s2[N];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  cin >> t;

  while (t--) {
    cin >> n;

    map <string, bool> first, second;
    for (int i = 1; i <= n; i++) {
      cin >> s1[i] >> s2[i];
    }

    bool flag = true;

    for (int i = 2; i <= n; i++) {
      if (first.find(s1[i]) != first.end()) {
        flag = false;
        break;
      }

      if (second.find(s2[i]) != second.end()) {
        flag = false;
        break;
      }

      if (s1[i] != s1[i - 1] && s2[i] != s2[i - 1]) {
        first[s1[i - 1]] = true;
        second[s2[i - 1]] = true;
      }
    }

    if (flag) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
  return 0;
}
