Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	var num int
	fmt.Scan(&num)

	for i := 0; i < num; i++ {
		sc.Scan()
		line := sc.Text()

		insertCheck(line)
	}
}

func insertCheck(line string) {
	var B, C []int

	for _, v := range strings.Split(line, " ") {
		ball, _ := strconv.Atoi(v)
		switch {
		case len(B) == 0:
			B = append(B, ball)
		case B[len(B)-1] < ball:
			B = append(B, ball)
		case B[len(B)-1] >= ball:
			switch {
			case len(C) == 0:
				C = append(C, ball)
			case C[len(C)-1] < ball:
				C = append(C, ball)
			case C[len(C)-1] >= ball:
				fmt.Println("NO")
				return
			}
		}
	}
	fmt.Println("YES")
}

C++: Public class Main {
	void run() {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] boll = new int[10];
		for(int k = 0; k < n; k++) {
			for(int i = 0; i < 10; i++) {
				boll[i] = scan.nextInt();
			}
			int judg = 0;
			for(int i = 0; i < n; i++) {
				int right,left;
				right = boll[0];
				left = 0;
				for(int m = 1; m < 10; m++) {
					if(right > boll[m]) {
						if(left < boll[m]) {
							left = boll[m];
						}
						else {
							judg = 0;
							break;
						}
					}
					else if(right < boll[m]) {
						right = boll[m];
					}
					judg = 1;
				}
				if(judg == 0) {
					System.out.println("NO");
				}
				else {
					System.out.println("YES");
				}
			}
		}
	}
	public static void main(String[] args) {
		new Main().run();
	}
}

C++: #include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<queue>
using namespace std;
int a,b,temp,n;
int main()
{
    int n;
    cin>>n;
    while(n--){
        queue<int>que;
        for(int i=0;i<10;i++){
            cin>>temp;
            que.push(temp);
        }
        while(que.size()){
            temp=que.front();
            que.pop();
            if(temp<=a&&temp<=b){
                cout<<"NO\n";
                return 0;
            }
            else if(temp<=a&&temp>b)b=temp;
            else if(temp<=b&&temp>a)a=temp;
            else {
                if(a>=b)a=temp;
                else b=temp;
            }
        }
        cout<<"YES\n";
    }

    return 0;
}

C++: #include <iostream>
using namespace std;

bool f(void){
	int a=0, b=0, e;
	for (int i=0; i<10; i++){
		cin>>e;
		if (e>a) a=e;
		else if (e>b) b=e;
		else return false;
	}
	return true;
}

int main(void){

	int n;

	cin>>n;
	while (n--){
		if (f()) cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

int main(void) {
    int N, a, b, c, x[10];
    cin >> N;
    for (; N--; ) {
        bool ok = true;
        b = c = 0;
        for (int i = 0; i < 10; i++) {
            cin >> x[i];
            a = x[i];
            if (a < b && a < c) {
                ok = false;
                break;
            } else if (a < b) {
                c = a;
            } else if (a < c) {
                b = a;
            } else if (b < c) {
                c = a;
            } else {
                b = a;
            }
        }
        if (ok) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    return 0;
}

C++: #define _USE_MATH_DEFINES

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <utility>
#include <vector>
#include <numeric>

using namespace std;

int main()
{
	int n;
	for (cin >> n; n--;)
	{
		vector<int> b;
		vector<int> c;

		for (int i = 0; i < 10; i++)
		{
			int x;
			cin >> x;

			if (i == 0)
			{
				b.push_back(x);
			}
			else if (i == 1)
			{
				c.push_back(x);
			}
			else
			{
				if (x > b.back() || x > c.back())
				{
					if (b.back() > c.back())
					{
						b.push_back(x);
					}
					else
					{
						c.push_back(x);
					}
				}
			}
		}

		cout << (b.size() + c.size() == 10 ? "YES" : "NO") << endl;
	}
}

C++: #include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<cctype>
#include<vector>
#include<algorithm>
#include<stack>
#include<queue>
#include<list>


using namespace std;

#define FOR(x) for(int i = 0; i < x; i++)

stack<short> left, right;
short a[10], n, j;

bool solve(short c, bool judge){
	if(c == 10) return true;
	if(left.top() < a[c]){
		left.push(a[c]);
		if(solve(c + 1, true)) return true;
	}
	if(right.top() < a[c]){
		right.push(a[c]);
		if(solve(c + 1, false)) return true;
	}
	if(judge) left.pop();
	else right.pop();
	return false;
}

int main(){
	scanf("%d", &n);
	FOR(n){
		left.push(0);
		right.push(0);
		for(j = 0; j < 10; j++)
			scanf("%d", &a[j]);
		if(solve(0, true)) printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}

C++: #include <stdio.h>

int
main(void)
{
	char line[80];

	int b[10];

	int n;
	
	if (fgets(line, sizeof line, stdin) == NULL) {
		return 0;
	}
	if (sscanf(line, "%d", &n) != 1) {
		return 0;
	}
	
	while (n--) {
		if (fgets(line, sizeof line, stdin) == NULL) {
			break;
		}
		if (sscanf(line, "%d %d %d %d %d %d %d %d %d %d",
				   &(b[0]), &(b[1]), &(b[2]), &(b[3]), &(b[4]), &(b[5]),
				   &(b[6]), &(b[7]), &(b[7]), &(b[9])) != 10) {
			break;
		}

		bool f = true;
		int s0 = 0;
		int s1 = 0;
		for (int t : b) {
			if (t > s0 && t > s1) {
				if (t - s0 <= t - s1) {
					s0 = t;
				} else {
					s1 = t;
				}
			} else 	if (t > s0) {
				s0 = t;
			} else 	if (t > s1) {
				s1 = t;
			} else {
				f = false;
				break;
			}
		}
		printf("%s\n", (f ? "YES" : "NO"));
	}

	return 0;
}

C++: #include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>

using namespace std;


#define all(c) ((c).begin()), ((c).end())
#define debug(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, a, b) for (int i = (int)(a); i <= (int)(b); i++)

#define mp make_pair
#define fst first
#define snd second
#define pb push_back


const double EPS = 1e-10;


typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef complex<double> P;

int main() {
	int n; cin >> n;
	while (n--) {
		int l = 0, r = 0;
		bool ok = true;
		rep(i, 10) {
			int b; cin >> b;
			if(l < b) l = b;
			else if (r < b) r = b;
			else ok = false;
		}
		cout << (ok ? "YES" : "NO" ) << endl;
	}
	return 0;
}