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 <bits/stdc++.h>
using namespace std;

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;

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

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

int n;
int a[11];

void bitBruteForth() {
   bool printed = false;
   rep (mask, (1<<10)) {
      bool ok = true;
      int oldA = -1, oldB = -1;
      rep (j, 10) {
         if ((mask>>j)&1) {
            if (a[j] > oldA) {
               oldA = a[j];
            } else {
               ok = false;
            }
         } else {
            if (a[j] > oldB) {
               oldB = a[j];
            } else {
               ok = false;
            }
         }
      }
      if (ok) {
         puts("YES");
         printed = true;
         break;
      }
   }
   if (!printed) puts("NO");
}

bool ans;

void rec(int idx, int l, int r) {
   if (idx == 10) {
      ans = true;
      return;
   }

   int val = a[idx];
   if (l < val) rec(idx+1, val, r);
   if (r < val) rec(idx+1, l, val);
}

int main() {
   cin >> n;
   while (n--) {
      rep (i, 10) cin >> a[i];
      ans = false;
      rec(0, -1, -1);
      puts(ans?"YES":"NO");
   }

   return 0;
}

C++: #include <iostream>
using namespace std;
int main() {
  bool f;
  int n, i, a, b, c;
  cin >> n;
  while (n--) {
    for (i = b = c = f = 0; i < 10; i++) {
      cin >> a;
      if (a > b) {
        b = a;
      } else if (a > c) {
        c = a;
      } else {
        f = 1;
      }
    }
    if (f)
      cout << "NO" << endl;
    else
      cout << "YES" << endl;
  }
  return 0;
}

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

main(){
    int n, B[10], P[2], b, s;
    cin >> n;
    for ( int t = 0; t < n; t++ ){
	for ( int i = 0; i < 10; i++ ) cin >> B[i];
	P[0] = P[1] = 0;
	bool p = true;
	for ( int i = 0; i < 10; i++ ){
	    if ( P[0] > P[1] ) { b = 0; s = 1; }
	    else { b = 1; s = 0;}
	    if ( B[i] > P[b] ) P[b] = B[i];
	    else if ( B[i] > P[s] ) P[s] = B[i];
	    else {p = false; break;}
	}
	if ( p ) cout << "YES" << endl;
	else cout << "NO" << endl;
    }
}

C++: #include <cstdio>

using namespace std;

int n;
int t[15], t1[15], t2[15];

bool yes;
void dfs(int n, int t1[], int num, int t2[])
{
    if(n == 10)
    {
        bool zen1=true, zen2 = true;
        for(int i=1; i<num; i++) if(t1[i]<t1[i-1]) zen1 = false;
        for(int i=1; i<10-num; i++) if(t2[i]<t2[i-1]) zen2 = false;
        if(zen1 && zen2) yes = true;
        return ;
    }
    t1[n+1] = t[n+1];
    dfs(n+1, t1, num+1, t2);
    t2[n+1] = t[n+1];
    dfs(n+1, t1, num, t2);
}

int main()
{
    scanf("%d", &n);
    while(n--)
    {
        for(int i=0; i<10; i++)
            scanf("%d", &t[i]);
        yes = false;
        dfs(0, t1, 0, t2);
        if(yes)
            printf("YES\n");
        else
            printf("NO\n");
    }
    return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int n,a,b=0,c=0;
  int i,j;
  int flag=0;
  cin >> n;
  for(i=0;i<n;i++){
    for(j=0;j<10;j++){
      cin >> a;
      if(b<a){
	b=a;
      }
      else if(c<a){
	c=a;
      }
      else{
	flag=1;
      }
    }
    if(flag==0)cout << "YES" << endl;
    if(flag==1)cout << "NO" << endl;
    b=0,c=0;
    flag=0;
  }
}

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

int a[10];
bool flag;
vector< int > l;
vector< int > r;
void dfs(int dep)
{
	if (flag) return;
	if(dep == 10) {
		flag = true;
		return;
	}
	if (l.size() == 0 || l.back() < a[dep]) {
		l.push_back(a[dep]);	
		dfs(dep + 1);
	}
	if (r.size() == 0 || r.back() < a[dep]) {
		r.push_back(a[dep]);
		dfs(dep + 1);
	}
}
int main()
{
	int t;
	cin >> t;
	for (int cas = 0; cas < t; cas++) {
		for (int i = 0; i < 10; i++) { cin >> a[i]; }
		flag = false;
		dfs(0);
		if (flag) cout << "YES\n";
		else cout << "NO\n";
	}
	return 0;
}

C++: 
#include <cstdio>
#include <vector>

using namespace std;

int  s[10];

int main()
{
	//freopen("in.txt", "r", stdin);

	int case_t, case_num;
	scanf("%d", &case_num);
	for (case_t=1; case_t<=case_num; case_t++) {
		int i;
		for (i=0; i<10; i++)
			scanf("%d", &s[i]);

		int min1 = -1, min2 = -1;

		for (i=0; i<10; i++) {
			if (s[i]<min1 && s[i]<min2)
				break;
			if (s[i]>min1 && s[i]>min2) {
				if (min1 < min2)
					min2 = s[i];
				else
					min1 = s[i];
			}
			else if (s[i]>min1)
				min1 = s[i];
			else
				min2 = s[i];

		}
		if (i<10) printf("NO\n");
		else printf("YES\n");


	}

	return 0;
}

C++: #include<stdio.h>
#include <iostream>
#include <vector>
#include <queue>
using namespace std;

bool flag = true;

void solve(queue<int> left, queue<int> right, queue<int> all) {
	if (all.size() > 0) {
		if (left.size() > 0) {
			if (all.front() > left.back()) {
				left.push(all.front());
				all.pop();
				solve(left, right, all);
			}
			else {
				if (right.size() > 0) {
					if (all.front() > right.back()) {
						right.push(all.front());
						all.pop();
						solve(left, right, all);
					}
					else if(all.size() == 0){
					
					}
					else {
						flag = false;
					}
				}
				else {
					right.push(all.front());
					all.pop();
					solve(left, right, all);
				}
			}
		}
		else {
			left.push(all.front());
			all.pop();
			solve(left, right, all);
		}
	}
}

int main() {

	int n;
	cin >> n;
	for (; n > 0; n--) {
		queue<int> all;
		queue<int> left;
		queue<int> right;
		for (int i = 0; i < 10; i++) {
			int temp;
			cin >> temp;
			all.push(temp);
		}
		solve(left, right, all);
		if (flag)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}



	
				   
}

C++: #include <cstdio>
#include <stack>
#define NUM 10
using namespace std;

int N;


int main()
{
	//freopen("in","r",stdin);
	scanf("%d",&N);
	while(N--){
		int tmp;
		bool sol=true;
		stack<int> B,C;
		for(int i=0;i<NUM;i++){
			
			scanf("%d",&tmp);
			if(B.empty())
				B.push(tmp);
			else if(tmp>B.top())
				B.push(tmp);
			else if(C.empty())
				C.push(tmp);
			else if(tmp>C.top())
				C.push(tmp);
			else
				sol = false;
		}
		if(sol)
			printf("YES\n");
		else
			printf("NO\n");
	}

	return 0;
}