#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <string>
#include <stack>
#include <iomanip>
#include <numeric>
#include <queue>
#include <climits>
#include <complex>
#include <cmath>
#include <map>
using namespace std;
using ll = long long;
#define MOD 1000000007
#define INF 1LL << 59

void solve()
{
    int arr[10];
    for (int i = 0; i < 10; ++i)
        cin >> arr[i];
    bool f = false;
    for (int bit = 0; bit < (1 << 10); ++bit)
    {
        bool judge = true;
        vector<int> v1, v2;
        for (int i = 0; i < 10; ++i)
        {
            if (bit >> i & 1)
                v1.push_back(arr[i]);
            else
                v2.push_back(arr[i]);
        }

        int n = v1.size();
        int m = v2.size();
        for (int i = 0; i < n - 1; ++i)
        {
            if (v1[i] < v1[i + 1])
                continue;
            else
                judge = false;
        }

        for (int i = 0; i < m - 1; ++i)
        {
            if (v2[i] < v2[i + 1])
                continue;
            else
                judge = false;
        }

        if (judge)
        {
            f = judge;
            break;
        }
    }
    if (f)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    //cout << fixed << setprecision(3);

    int n;
    cin >> n;
    while (n--)
    {
        solve();
    }
    return 0;
}
