#include <iostream>
#include <vector>
using namespace std;

int main() {
    int n;
    cin >> n;
    while (n--) {
        vector<int> a(10);
        for (vector<int>::iterator it = a.begin(); it != a.end(); it++) {
            cin >> *it;
        }
        bool no = false;
        vector<int> b, c;
        b.push_back(0);
        c.push_back(0);
        for (vector<int>::iterator it = a.begin(); it != a.end(); it++) {
            cout << "insert " << *it << " to  " << b.back() << " " << c.back() << endl;
            if (b.back() < c.back()) {
                if (*it > c.back()) {
                    c.push_back(*it);
                } else if (*it > b.back()) {
                    b.push_back(*it);
                } else {
                    no = true;
                    break;
                }
            } else {
                if (*it > b.back()) {
                    b.push_back(*it);
                } else if (*it > c.back()) {
                    c.push_back(*it);
                } else {
                    no = true;
                    break;
                }
            }
            cout << "result " << b.back() << " " << c.back() << endl;
        }
        if (no) {
            cout << "NO" << endl;
        } else {
            cout << "YES" << endl;
        }
    }
}