#include <iostream>
#include <vector>

using namespace std;

bool solve(int bl, int cl,vector<int>& a, int i) {
    if( i == 9 ) return true;
    else {
        int t = a[i];
        return ( t > bl && solve(t,cl,a,i+1) ) ||
               ( t > cl && solve(bl,t,a,i+1) );
    }
}

int main(){
    int n;
    cin >> n;
    while(n--){
        vector<int> a(9);
        int fst;
        cin >> fst;
        for(int i=0;i<9;++i){
            cin >> a[i];
        }

        if( solve(fst, 0, a, 0) ) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }
    return 0;
}