#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl;
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    int n;
    cin >> n;
    rep(i, n)
    {
        stack<int> b, c;
        int a[10];
        bool flag = 0;
        rep(i, 10) cin >> a[i];

        b.push(a[0]);
        c.push(0);
        for (int i = 1; i < 10; i++)
        {
            int dis1 = a[i] - b.top(), dis2 = a[i] - c.top();
            if (dis1 < 0 && dis2 < 0)
            {
                flag = 1;
                break;
            }
            if (dis1 < dis2 && dis1 > 0)
            {
                b.push(a[i]);
            }
            else
            {
                c.push(a[i]);
            }
        }
        if (flag == 0)
        {
            OP("YES")
        }
        else
        {
            OP("NO")
        }
    }

    return 0;
}
