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++: #include <stdio.h>
#include <vector>
#include <iostream>

using namespace std;

int main() {
	vector<int> left;
	vector<int> right;
	vector<int> all;

	bool flag = true;

	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			int temp;
			cin >> temp;
			all.push_back(temp);
		}
	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			if (left.size() > 0) {
				if (all[10 * i + j] > left[left.size() - 1]) {
					left.push_back(all[10 * i + j]);
				}
				else {
					if (right.size() > 0) {
						if (all[10 * i + j] > right[right.size() - 1])
							right.push_back(all[10 * i + j]);
						else
							flag = false;
					}
					else {
						right.push_back(all[10 * i + j]);
					}
				}
			}
			else {
				left.push_back(all[10 * i + j]);
			}
		}

		if (flag)
			cout << "YES" << endl;
		else
			cout << "NO"<<endl;
		flag = true;
	}
}

C++: #include<stdio.h>

#include<string.h>

int a[13], vis[13], flag;

void dfs(int x, int l, int r)
{

    int i;

    if(x == 11) return; 

    if(flag) return ;

    if(a[x] > l) dfs(x + 1, a[x], r);

    else  if(a[x] > r) dfs(x + 1, l, a[x]);

    else  {flag = 1; return;}
}

int main()

{

	int T, i, j, k;

	scanf("%d", &T);

	while(T--)

	{

		flag = 0;

		for(i = 1; i <= 10; i++)

		scanf("%d", &a[i]);

		memset(vis, 0, sizeof(vis));

		dfs(1, 0, 0);

		if(flag) printf("NO\n");

		else printf("YES\n");

	}

return 0;

}

C++: #include <iostream>
using namespace std;
int main (){
	int N;
	int L = 0;
	int R = 0;
	cin >> N;
	int T[N][10];
	for (int i = 0; i < N; ++i)
	{
		for (int j = 0; j < 10; ++j)
		{
			cin >> T[i][j];			
		}
	}
	for (int i = 0; i < N; ++i)
	{
		for (int j = 0; j < 10; ++j)
		{
			if(L < T[i][j]){
				L = T[i][j];
				if(j == 9){
					cout << "YES\n";
				}
			}else if(R < T[i][j]){
				R = T[i][j];
				if(j == 9){
					cout << "YES\n";
				}
			}else{
				cout << "NO\n";
				break;
			}
		}
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>

using namespace std;

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

C++: 
#include <cstdio>

const int MAXN = 15;
int a[MAXN], flag;

void dfs(int p, int b, int c)
{
    if(p == 10)
    {
        flag = 1;
        return;
    }
    if(a[p] > b) dfs(p + 1, a[p], c);
    if(a[p] > c) dfs(p + 1, b, a[p]);
}

int main()
{
    int t;
    while(~scanf("%d", &t))
    {
        while(t--)
        {
            flag = 0;
            for(int i = 0; i < 10; i++)
                scanf("%d", &a[i]);
            dfs(0, 0, 0);
            printf("%s\n", flag ? "YES" : "NO");
        }
    }
    return 0;
}

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

int n;
int has_put;
int a[10];

int main() {
    scanf("%d", &n);
    for (int T=0; T<n; T++) {
        for (int i=0; i<10; i++) {
            scanf("%d", &a[i]);
        }

        has_put = 0;
        for (int bit=0; bit<1024; bit++) {
            int pre1 = -1;
            int pre2 = -1;
            int possible = 1;

            for (int i=0; i<10; i++) {
                if ((bit>>i)&1) {
                    if (a[i] < pre1) {
                        possible = 0;
                        break;
                    }
                    pre1 = a[i];
                } else {
                    if (a[i] < pre2) {
                        possible = 0;
                        break;
                    }
                    pre2 = a[i];
                }
            }

            if (possible) {
                puts("YES");
                has_put = 1;
                break;
            }
        }

        if (!has_put) {
            puts("NO");
        }
    }
}

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

int main() {
  int n;
  cin >> n;
  int t;
  int i, j;
  for (i = 0; i < n; i++) {
    queue<int> q;
    for (j = 0; j < 10; j++) {
      cin >> t;
      q.push(t);
    }
    stack<int> a, b;
    a.push(q.front());
    q.pop();
    b.push(0);
    while (q.size()) {
      if (a.top() < q.front()) {
        a.push(q.front());
      } else if (b.top() < q.front()) {
        b.push(q.front());
      } else {
        cout << "NO" << endl;
        break;
      }
      q.pop();
      if (q.size() == 0) {
        cout << "YES" << endl;
      }
    }
  }
  return 0;
}

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

int n,b[10];

bool dfs(int l, int r, int c)
{
	if(c==10) return true;

	if(l<b[c])
	{
		if(dfs(b[c],r,c+1)) return true;
	}
	if(r<b[c])
	{
		if(dfs(l,b[c],c+1)) return true;
	}
	return false;
}


int main()
{
	cin >> n;
	while(n--)
	{
		for(int i=0; i<10; i++) cin >> b[i];
		cout << ( dfs(0,0,0)? "YES":"NO" ) << endl;
	}
}

C++: #include<cstdio>

int main(void){
	int n,i,j;
	int a[1024][10];
	scanf("%d",&n);
	for(i=0;i<n;i++){
		for(j=0;j<10;j++){
			scanf("%d",&a[i][j]);
		}
	}
	
	for(i=0;i<n;i++){
		int b[10],c[10];
		b[0]=a[i][0];
		bool x=true;
		int k=0,l=0;
		for(j=1;j<10;j++){
			if(a[i][j]>b[k]){
				k++;
				b[k]=a[i][j];
			}else {
				c[l]=a[i][j];
				l++;
			}
		}

		for(j=0;j<l-2;j++){
			if (c[j]>c[j+1]){
				x=false;
			}
			//if(c[j]>c[j+1]) break;
		}
		if(x==true){
			printf("Yes\n");
		} else{
			printf("No\n");
		}	
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

#define iota(i,n,b,s) for(int i=int(b);i!=int((b)+(s)*(n));i+=(s))
#define range(i,n,m) iota(i,(((n)>(m))?((n)-(m)):((m)-(n))),(n),((n)>(m)?-1:1))
#define rep(i,n) iota(i,(n),0,1)
#define loop for(;;)

#define INF (1e9)
#define EPS (1e-9)
#define cons(a,b) (make_pair(a,b))
#define car(a) (a.first)
#define cdr(a) (a.second)
#define cadr(a) (car(cdr(a)))
#define cddr(a) (cdr(cdr(a)))
#define all(a) a.begin(), a.end()
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;

typedef long long Integer;
typedef double Real;
typedef vector<int> vi;
typedef vector<string> vs;
typedef map<string,int> Dictionary;
const Real PI = acos(-1);

template<class S, class T>
ostream& operator<<(ostream& os, pair<S,T> p) {
  os << '(' << car(p) << ", " << cdr(p) << ')';
  return os;
}

template<class T>
ostream& operator<<(ostream& os, vector<T> v) {
  if (v.size() == 0) {
    os << "(empty)";
    return os;
  }
  os << v[0];
  for (int i=1, len=v.size(); i<len; ++i) os << ' ' << v[i];
  return os;
}

int dx[] = { -1, 0, 1, 0 };
int dy[] = {  0, -1, 0, 1 };

bool
f(vector<int>&ln, int idx, int x, int y) {
  if (idx == 10) return true;
  int z = ln[idx];
  return (x < z && f(ln, idx + 1, z, y)) || (y < z && f(ln, idx + 1, y, z));
}

int main() {

  int n; cin >> n;
  for (;n--;) {
    vector<int> ln(10);
    rep (i, 10) cin >> ln[i];
    bool bl = f(ln, 0, 0, 0);
    cout << (bl ? "YES" : "NO" ) <<endl;
  }

  return 0;
}