Go: package main

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

var scanner = bufio.NewScanner(os.Stdin)

func nextInt() int {
	scanner.Scan()
	i, e := strconv.Atoi(scanner.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	scanner.Split(bufio.ScanWords)
	n := nextInt()
	for i := 0; i < n; i++ {
		a := -1
		b := -1
		ans := true
		// それぞれの筒の一番上にあるたまの数字に着目すればよい
		for j := 0; j < 10; j++ {
			x := nextInt()
			if x > a {
				a = x
			} else if x > b {
				b = x
			} else {
				ans = false
			}
		}
		if ans {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

C++: #include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <string>
#include <algorithm>
#include <climits>
#include <utility>

#define PRINT(STR) cout << STR << endl;
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); (i)++)
#define REG(i, a, b) for (int (i) = ((int)(a)); (i) < ((int)(b)); i++)
#define ALL(V) (V).begin(), (V).end()
#define SPACE " "

typedef long long ll;

using namespace std;

int nextInt() { int n = -1; cin >> n; return n; }
double nextDouble() { double d = -1; cin >> d; return d; }
ll nextll() { ll n = -1; cin >> n; return n; }
string nextString() { string str; cin >> str; return str; }

int INF = 1LL << 25;
double EPS = 1e-9;
int numofbits(int bits)
{
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

// BEGIN //////////////////////////////////////////////////////////////
int main() {
  int N = nextInt();
  REP(i, N) {
    stack<int> bs, cs;
    bool flag = true;
    bs.push(0);
    cs.push(0);
    REP(j, 10) {
      int a = nextInt();
      if (bs.top() < a) {
        if (cs.top() < a) {
          if (bs.top() > cs.top()) {
            bs.push(a);
          } else {
            cs.push(a);
          }
        } else {
          bs.push(a);
        }
      } else if (cs.top() < a) {
        cs.push(a);
      } else {
        flag = false;
        break;
      }
    }
    if (flag) {
      PRINT("YES");
    } else {
      PRINT("NO");
    }
  }
	return 0;
}
// END   //////////////////////////////////////////////////////////////

C++: #include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>

using namespace std;

int main(){
    int n,b,B=0,C=0;
    
    scanf("%d",&n);
    
    for(int i=0;i<n;i++){
        B=0;C=0;
        for(int j=0;j<10;j++){
            scanf("%d",&b);
            if(B==0 || B==b-1)
                B=b;
            else if(C==0 || C==b-1)
                C=b;
            else{
                B=0;C=0;
                break;
            }
        }
        if(B==10 || C==10)
            puts("YES");
        else
            puts("NO");
    }
}

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

using namespace std;

int main() {
	int A[10];
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++)
			cin >> A[j];
		stack<int> B, C;
		string ans = "YES";
		for (int j = 0; j < 10; j++) {
			int k = A[j];
			if (B.empty() == true && C.empty() == true)
				B.push(k);
			else if (B.empty() != true && C.empty() == true) {
				if (B.top() < k)
					B.push(k);
				else
					C.push(k);
			}
			else {
				if (B.top() > k && C.top() > k) {
//					cout << k << " " << B.top() << " " << C.top() << endl;
					ans = "NO";
					break;
				}
				else if (B.top() > C.top())
					B.push(k);
				else
					C.push(k);
			}
		}
		cout << ans << endl;
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
bool canbe = false;
string inp;

void dfs(int b, int c, int depth){
    if (depth >= 9){ canbe = true; return; }
    if (inp[depth] - '0' < b && inp[depth] - '0' < c) return;

    if (inp[depth] - '0' > b) dfs(inp[depth] - '0', c, depth+1);
    if (inp[depth] - '0' > c) dfs(b, inp[depth] - '0', depth+1);
}


int n;
int main(){
    cin >> n;
    for (int i = 0; i < n; i++){
	canbe = false;
	inp = "";
	string g;
	for (int j = 0; j < 10; j++){
	    cin >> g;
	    inp += g;	    
	}
	dfs(0, 0, 0);

	if (canbe) cout << "YES" << endl;
	else cout << "NO" << endl;
    }
}

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--) {
		fgets(line, sizeof line, stdin);
		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]));

		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>
main(){
int n,i,A,B,C,f;
for(std::cin>>n;n-->0;puts(f?"NO":"YES"))
 for(B=C=f=i=0;i++<10;){
  std::cin>>A;
  if(B<A)B=A;else C<A?C=A:f=1;
 }
}

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

int B[11]={0};
int C[11]={0};

bool DFS(int *a,int i=0,int b=1,int c=1)
{
	bool judge=true;

	if(i==10)
		return judge;

	judge=false;

	if(B[b-1]<a[i]){
		B[b]=a[i];
		judge=DFS(a,i+1,b+1,c);
		
	}
	if(C[c-1]<a[i]){
		C[c]=a[i];
		judge=DFS(a,i+1,b,c+1);
		
	}

	return judge;
}        

int main()
{
        int N;
	int i=0;
        cin>>N;

		while(i<N){
			int A[10]={0};
			for(int i=0;i<10;i++)
				cin>>A[i];

            ??????????????????if(DFS(A)==true)
                ????????????????????????cout<<"YES"<<endl;
            ??????????????????else
		????????????????????????cout<<"NO"<<endl;

	????????????????????????i++;
        }
                
	
        return 0;
}

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

using namespace std;

int main(){
  int f;
  int n;
  int in,b,c;
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    f=b=c=0;
    for(int j=0;j<10;j++){
      scanf("%d",&in);
      if(!f){
	if(in<=min(b,c)){
	  f=1;
	}
	if((b>=c && b<in)||(b<c && c>in))b=in;
	else c=in;
      }
    }
    if(f)printf("NO\n");
    else printf("YES\n");
  }
}

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

int arr[10];
bool flag;

void dfs(int num, int l, int r) {
  if(num==10) {
    flag = true;
    return;
  }

  if(arr[num] > l) dfs(num+1, arr[num], r);
  if(arr[num] > r) dfs(num+1, l, arr[num]);
  return;
}

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

    flag = false;
    dfs(0,0,0);
    if(flag)
      printf("YES\n");
    else
      printf("NO\n");
  }
}

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

using namespace std;

bool yes;
int ball[10];

void print(deque <int> a){
	for (int i = 0; i < a.size(); i++){
		cout << a[i] << " ";
	}
	cout << endl;
}

void rec(deque <int> b, deque <int> c, int num)
{
	if (num >= 10){
		yes = true;
		return;
	}

	if (b.back() < ball[num]){
		b.push_back(ball[num]);
		rec(b, c, num + 1);
		b.pop_back();
	}
	if (c.back() < ball[num]){
		c.push_back(ball[num]);
		rec(b, c, num + 1);
		c.pop_back();
	}

	return;
}

int main(void)
{
	int n;
	cin >> n;
	while (n--){
		for (int i = 0; i < 10; i++){
			cin >> ball[i];
		}

		yes = false;
		deque <int> b, c;
		b.push_back(-1);
		c.push_back(-1);
		rec(b, c, 0);
		if (yes){
			cout << "YES" << endl;
		}
		else {
			cout << "NO" << endl;
		}
	}
}