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 <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> x, y;
short a[10], n, j, i;

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

int main(){
	scanf("%d", &n);
	for(i = 0; i < n; i++){
		x.push(0);
		y.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++: /*
 * Main.cpp
 *
 *  Created on:
 *      Author: KC
 */
/*
 ID: chancha4
 PROG: packrec
 LANG: C++
 */
#include <iostream>
#include <fstream>
#include <algorithm>
#include <cstdio>
#include <string>
#include <cstring>
#include <sstream>
#include <math.h>
#include <vector>
#include <time.h>
#include<stack>
#include <set>
#include <limits>
#include<map>
#include<utility>

using namespace std;

int n = 10;
int e[11];

bool solve(int lv, int topa, int counta, int topb, int countb){
    bool boola;
    bool boolb;
    if(lv == n) return ((counta + countb) == n) ;

    if(topa < e[lv]) boola = solve(lv + 1, e[lv], counta + 1, topb, countb);
    else boola = false;

    if(topb < e[lv]) boolb = solve(lv + 1, topa , counta, e[lv], countb + 1);
    else boolb = false;

    return (boola || boolb);


}
int main(){
    int T;
    scanf("%d", &T);
    for(int i = 0; i < T; i++){
        for(int j = 0; j < 10; j++) scanf("%d", e + j);
        bool res = solve(0, 0, 0, 0, 0);
        if(res) puts("YES");
        else puts("NO");

    }
}

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

int main()
{
    int n;
    cin >> n;

    while (n--) {
        int left = 0, right = 0;
        bool flag = true;
        for (int i = 10; i--;) {
            int x;
            cin >> x;
            if (x > left && right)
                left = x;
            else if (x > right)
                right = x;
            else {
                flag = false;
                break;
            }
            if (left < right)
                swap(left, right);
        }
        cout << (flag ? "YES" : "NO") << endl;
    }

    return 0;
}

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 rec(int idx, int l, int r) {
   if (idx == 10) return true;

   bool x = false, y = false;
   int val = a[idx];
   if (l < val) x = rec(idx+1, val, r);
   if (r < val) y = rec(idx+1, l, val);

   return x || y;
}

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

   return 0;
}

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

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

int main(){
	int b, c, n, a, i, j;
	bool executable;
	cin >> n;
	for(i=0;i<n;i++){
		executable = true;
		cin>>a;
		b=a;
		c=0;
		for(j=1;j<10;j++){
			cin>>a;
			if(a-b < 0){
				if(a-c < 0){
					executable = false;
				}else{
					c = a;
				}
			}else{
				if(a-c < 0){
					b = a;
				}else{
					if(c < b){
						b = a;
					}else{
						c = a;
					}
				}
			}
		}
		if(executable){
			cout << "YES\n";
		}else{
			cout << "NO\n";
		}
	}
	return 0;
}

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

int main(){
  int n=0;
  int a[10];
  int ans=0;
  cin>>n;
  //  while(scanf("%d %d %d %d %d %d %d %d %d %d",&a[0],&a[1],&a[2],&a[3],&a[4],&a[5],&a[6],&a[7],&a[8],&a[9])){
  for(int j=0;j<n;j++){
    for(int k=0;k<10;k++){
      cin>>a[k];
    }
    ans=0;
    int l=0,r=0;
    for(int i=0;i<10;i++){
      if(i==0){
	l=a[i];
      }
      else{
	int ma=max(l,r);
	int mi=min(l,r);
	if(a[i]>ma){
	  if(l==ma){
	    l=a[i];
	  }
	  else{
	    r=a[i];
	  }
	}
	else if(mi<a[i]&&a[i]<ma){
	  if(l==mi){
	    l=a[i];
	  }
	  else{
	    r=a[i];
	  }
	}
	else{
	  break;
	}
      }
      if(i==9){
	ans=1;
      }
    }

    if(ans==1){
      cout<<"YES\n";
    }
    else{
      cout<<"NO\n";
    }
  }
  return 0;
}

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

using namespace std;
vector<int> ball;
bool search(int l, int r, int n)
{
  if (n == 10) {
    return true;
  }

  if (l < ball[n]) {
    if (search(ball[n], r, n + 1)) {return true;}
  } 
  if (r < ball[n]) {
    if (search(l, ball[n], n + 1)) {return true;}
  }
  return false;
}

int main()
{
  int N;
  scanf("%d ", &N);
  
  for (int i = 0; i < N; i++) {
    ball.clear();
    ball.resize(10);
    for (int i = 0; i < 10; i++) {
      scanf("%d ", &ball[i]);
    }
    if (search(ball[0], 0, 1)) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }
  return 0;
}