#include <bits/stdc++.h>
using namespace std;
int a[15]{0}, b[10]{0};
int main(void) {
    int t;
    cin.sync_with_stdio(false);
    cin >> t;
    while (t--) {
        memset(a, 0, sizeof a);
        memset(b, 0, sizeof b);
        int cnt1 = 0, cnt2 = 0, x;
        bool flag = true;
        for (int i = 1; i <= 10; ++i) {
            cin >> x;
            if (x < a[cnt1] && x < b[cnt2]) {
                printf("NO\n");
                flag = false;
                break;
            } else if (x > a[cnt1] && x < b[cnt2]) {
                a[++cnt1] = x;
            } else if (x > b[cnt2] && x < a[cnt1]) {
                b[++cnt2] = x;
            } else if (x > b[cnt2] && x > a[cnt1]) {
                if(b[cnt2] > a[cnt1])
                    b[++cnt2] = x;
                else
                    a[++cnt1] = x;
                
            }
        }
        if (flag) printf("YES\n");
    }
    return 0;
}
