#include <iostream>
#include <vector>
#include <queue>
#define rep(i,n) for(int i = 0;i < n;i++)
#define req(i,n) for(int i = 1; i<n;i++)
using namespace std;
int main() {
    int n; cin >> n;
    rep(q, n) {
        vector<int> a(10);
        rep(j, 10) cin >> a[j];
        bool ok = 1;
        rep(j, a.size() - 1) {
            if (a[j] > a[j + 1]) {
                ok = 0;
                break;
            }
        }
        if (ok) {
            cout << "YES" << endl;
            continue;
        }
        req(bit, 1 << 10) {
            if (bit == 1023) {
                cout << "NO" << endl;
                break;
            }
            vector<int> b, c;int cnt = 0;
            rep(j, 10) {
                if (bit & (1 << j)) {
                    cnt++;
                    b.push_back(a[j]);
                }
                else c.push_back(a[j]);
            }
            bool ch = 1,ok=1;
            rep(j, b.size() - 1) {
                if (b[j] > b[j + 1]) {
                    ch = 0;
                    break;
                }
            }rep(j, c.size() - 1) {
                if (c[j] > c[j + 1]) {
                    ok = 0;
                    break;
                }
            }
            if (ok && ch) {
                cout << "YES"  << endl;
                break;
            }
        }
    }
}
