#include using namespace std; using ll = long long; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); int t; cin >> t; while (t--) { int n; cin >> n; bool ok = true; while (n--) { vector a(5); rep(i, 5) cin >> a[i]; if (a[0] != a[2]) ok = false; if (a[1] != a[3]) ok = false; if (a[3] != a[4]) ok = false; if (a[0] == a[1]) ok = false; } cout << (ok ? "Yes" : "No") << endl; } return 0; }