#include <iostream>

using namespace std;

int main() {
    int n;
    cin >> n;
    int data[10];
    while (n--) {
        for (int i = 0; i < 10; ++i) {
            cin >> data[i];
        }
        bool ans = true;
        int l, r;
        l = r = 0;
        for (int j = 0; j < 10; ++j) {
            if (data[j] > l)
                l = data[j];
            else if (data[j] > r)
                r = data[j];
            else {
                ans = false;
                break;
            }
        }
        if (ans)
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }

    return 0;
}
