#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
    int n, tmp;
    vector<int> vb, vc, vb_, vc_;
    
    cin >> n;
    
    for(int i = 0;i < n;i++){
        vb.clear();
        vc.clear();
        vb_.clear();
        vc_.clear();
        
        for(int j  = 0;j < 10;j++){
            cin >> tmp;
            
            if(j%2 != 0){
                vb.push_back(tmp);
            }else{
                vc.push_back(tmp);
            }
        }
        
        vb_ = vb;
        vc_ = vc;
        
        sort(vb.begin(), vb.end());
        sort(vc.begin(), vc.end());
        
        if(vb_ == vb && vc_ == vc){
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }
        
    }
    
    return 0;
}