#include<iostream>
#include<vector>
using namespace std;
int main(){

  int n,i;
  cin >> n;
  for(i=0;i<n;i++){
    int j;
    int tmp;
    int han=0;
    vector<int>in1;
    vector<int>in2;
    for(j=0;j<5;j++){
      cin >> tmp;
      in1.push_back(tmp);
      cin >> tmp;
      in2.push_back(tmp);
    }
    for(j=1;j<5;j++){
      if(in1[j-1]>in1[j])
	han=1;
      if(in2[j-1]>in2[j])
	han=1;
    }

    if(han==0)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }


}