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;

typedef long long ll;
typedef unsigned long long ull;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define foreach(itr,a) for(__typeof((a).begin()) itr=(a).begin(); itr!=(a).end(); itr++)
#define ALL(x) (x).begin(), (x).end()
#define pb push_back

int a[11];

void dfs(int depth, int l, int r) {
    if(depth == 10) {
        cout << "YES" << endl;
        return ;
    }

    int t = a[depth];
    if(l < t)
        dfs(depth+1, t, r);
    else if(r < t)
        dfs(depth+1, l, t);
    else
        cout << "NO" << endl;

    return ;
}

int main() {
    int n; cin >> n;
    rep(poyo,n) {
        rep(i,10) cin >> a[i];
        dfs(0,0,0);
    } 

    return 0;
}

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

int main(){
	int n,ball,tp[2],con,bad;
	
	cin >> n;
	
	for(; n > 0; n--){
		
		tp[0] = tp[1] = 0;
		
		for(int i = 0; i < 10; i++){
			cin >> ball;
			
			if(tp[0] > tp[1]){
				con = 0;
			}else{
				con = 1;
			}
			
			if(ball > tp[con]){
				tp[con] = ball;
			}else if(ball > tp[!con]){
				tp[!con] = ball;
			}else{
				cout << "NO" << endl;
				cin.ignore(64, '\n');
			}
			
			if(i == 9){
				cout << "YES" << endl;
			}
		}
	}
	
	return 0;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	vector<bool>l;
	int o[10], n;
	cin >> n;
	for (int i = 0; i < n; i++){
		for (int j = 0; j < 10; j++)
			cin >> o[i];
		int sum = o[i], num = 0;
		for (int k = 0; k < 10;k++) {
			if (o[k] < sum){
				num++;
				sum = o[k];
			}
		}
		l.push_back(!(num >= 2));
	}
	for (bool b : l) {
		if (!b)cout << "YES";
		else cout << "NO";
		cout << endl;
	}
	char c;
	cin >> c;
}

C++: #include<iostream>
using namespace std;
int main(){
  int t;
  cin >> t;
  int n[10];
  int b[10]={0};
  int c[10]={0};
  int bcount=0,ccount=0,h=0;
  for(int i=0;i<t;i++){
    for(int j=0;j<10;j++) cin >> n[j];
    for(int j=0;j<10;j++){
      if(b[0]==0) b[bcount] = n[j];
      else if(b[bcount]>c[ccount]&&b[bcount]<n[j]){
    bcount++;
    b[bcount] = n[j];
      }
      else if(c[ccount]>b[bcount]&&c[ccount]<n[j]){
    if(c[ccount]!=0) ccount++;
    c[ccount] = n[j];
      }
      else if(b[bcount]>c[ccount]&&b[bcount]>n[j]&&c[ccount]<n[j]){
    if(c[ccount]!=0) ccount++;
    c[ccount] = n[j];
      }
      else if(c[ccount]>b[bcount]&&c[ccount]>n[j]&&b[bcount]<n[j]){
    bcount++;
    b[bcount] = n[j];
      }
      else if(b[bcount]>n[j]&&c[ccount]>n[j]){
    cout << "NO" << endl;
    h = 1;
    break;
      }
    }
    if(h==0) cout << "YES" << endl;
    for(int i=0;i<10;i++){
      b[i] = 0;
      c[i] = 0;
    }
      bcount = 0;
      ccount = 0;
      h = 0;
  }
  return 0;
}

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

int main(){
	int n,a,flag;
	stack<int> b,c;
	cin >> n;
	for (int i = 0; i < n; i++){
		while (b.size()) b.pop();
		while (c.size()) c.pop();
		flag = 0;
		b.push(0);
		c.push(-1);
		for (int j = 0; j < 10; j++) {
			cin >> a;
			if (b.top() > c.top()){
				if (c.top() > a) flag = 1;
				else if (b.top() > a) c.push(a);
				else b.push(a);
			}
			else {
				if (b.top() > a) flag = 1;
				else if (c.top() > a) b.push(a);
				else c.push(a);
			}
		}
		if (flag) cout << "NO" << endl;
		else cout << "YES" << endl;
	}
}

C++: #include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <iostream>
using namespace std;
int n;
int a[15],b[15],c[15];
bool dfs(int i,int j)
{
    if(i + j == 10)
        return true;
    if(a[i] > b[i - 1]){
        b[i] = a[i];
        dfs(i + 1,j);
    }
    else
    {
        if(a[j] > c[j - 1]){
            c[j] = a[i];
            dfs(i,j + 1);
        }
    }
}
int main()
{
    while(~scanf("%d",&n))
    {
        while(n --){
            for(int i = 0; i < 10; i++)
                scanf("%d",&a[i]);
            memset(b,0,sizeof(b));
            memset(c,0,sizeof(c));
            int ans = dfs(0,0);
            if(ans == true)
                printf("YES\n");
            else
                printf("NO\n");
        }
    }
    return 0;
}

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

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

#define INF INT_MAX/3
#define vc vector<int>
#define MIN(a,b) (a>b?b:a)
#define MAX(a,b) (a>b?a:b)
#define pi 2*acos(0.0)
#define ll long long
#define eps 1e-14
int dx[] = { 1,-1,0,0,0 };
int dy[] = { 0,0,1,-1,0 };


int x[10];
vc ans;
void solve() {
	int left, r;
	left = x[0];
	r = 0;
	//?????¨?????§??§??????????????§?????¶??????????????´???????????\??????
	for (int i = 1; i < 10; i++) {
		//???????????¶??????????????????
		if (left > x[i] && r > x[i]) {
			//cout << "NO" << endl;
			ans.push_back(0);
			return;
		}
		//?????????????????¶????????????
		if (x[i] < left && r < x[i]){
			r = x[i];
			continue;
		}
		else if (x[i] < r&&left < x[i]) {
			left = x[i];
			continue;
		}
		else { //???????????????????????´???
			if (r < left) {
				left = x[i];
				continue;
			}
			else {
				r = x[i];
				continue;
			}
		}
		
	}
	//cout << "Yes" << endl;
	ans.push_back(1);
}

int main() {
	int n;
	cin >> n;
	REP(i, n) {
		REP(j, 10)
			cin >> x[j];
		solve();
	}
	for (int i = 0; i < ans.size(); i++) {
		if (ans[i] == 0)
			cout << "NO" << endl;
		else
			cout << "YES" << endl;
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int N;
  cin>>N;
  while(N--){
    int B,C=0,i=0,b[10];
    bool f=true;
    cin>>b[0]>>b[1]>>b[2]>>b[3]>>b[4]>>b[5]>>b[6]>>b[7]>>b[8]>>b[9];
    while(i<10){
      if(b[i]<B&&b[i]<C){
	f=false;break;
      }else if(B<b[i]){
	if(B<C&&C<b[i])C=b[i];
	else B=b[i];
      }else if(C<b[i]){
	C=b[i];
      }
      i++;
    }
    cout<<(f?"YES":"NO")<<endl;
  }
  return 0;
}

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--){
        int flag=1;
        a=0,b=0;
        queue<int>que;
        //while(que.size())que.pop();
        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";
                flag=0;
                break;
            }
            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;
            }
        }
        if(flag)cout<<"YES\n";
    }

    return 0;
}