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 <iostream>
#include <algorithm>

#include <string.h>

#define INT_INF 11

int a[10];

int memo[10+1][10+1][10+1];

int search(int i, int j, int k)
{
  if (memo[i][j][k] >= 0)
    return memo[i][j][k];
  
  if (i == 10)
    return memo[i][j][k] = INT_INF;

  int r = 0;

  if (a[i] > j)
    r = std::max(search(i + 1, a[i], k), r);
		 
  if (a[i] > k)
    r = std::max(search(i + 1, j, a[i]), r);
  
  return memo[i][j][k] = r;
}

int main(int argc, char** argv)
{
  int N;

  std::cin >> N;

  while (N --) {
    for (int i = 0; i < 10; i ++)
      std::cin >> a[i];

    memset(memo, -1, sizeof(memo));

    std::cout << (search(0, 0, 0) ? "YES" : "NO") << std::endl;
  }
}

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

using namespace std;

int main(){
  int N;
  cin>>N;
  while(N--){
    int h=0,l=0;
    bool fail=false;
    for(int i=0;i<10;i++){
      int n;
      cin>>n;
      if(h<n){
	h=n;
      }else if(l<n){
	l=n;
	if(h<l){
	  swap(h,l);
	}
      }else{
	fail=true;
      }
    }
    cout<<((fail)?"NO":"YES")<<endl;
  }
  return 0;
}

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

int a[10];
vector<int> b,c;

bool dfs(int i) {
  if (i == 10) {
    // 判定
    for (int j = 1; j < b.size() - 1; j++) {
      if (b[j] < b[j-1])
        return false;
    }
    for (int j = 1; j < c.size() - 1; j++) {
      if (c[j] < c[j-1])
        return false;
    }
    return true;
  }

  bool res = false;

  b.push_back(a[i]);
  res = res || dfs(i+1);
  b.pop_back();
  c.push_back(a[i]);
  res = res || dfs(i+1);
  c.pop_back();

  return res;
}

int main() {
  // ifstream ifs( "test.txt" );
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    // 入力
    for (int j = 0; j < 10; j++) {
      cin >> a[j];
    }
    b.clear();
    c.clear();
    // 計算
    bool res = dfs(0);
    // 出力
    cout << ((res) ? "YES" : "NO")<< endl;
  }
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <map>
using namespace std;

#define FOR(i,a,b) for(long long int i=(a);i<(b);i++)
#define REP(i,n) for(long long int i=0;i<(n);i++)
#define ALL(s) (s).begin(),(s).end()

#define PI 3.14159265358479

typedef long long ll;

int n, k, b = 0, c = 0;
bool f = 1;
stack<int> sb, sc;

int main(){
	cin >> n;
	REP(i, n){
		REP(j, 10){
			cin >> k;
			if (b == 0){
				sb.push(k);
				b++;
			}
			else if (c == 0){
				sc.push(k);
				if (sb.top() < k){
					sc.push(sb.top());
					sb.push(k);
				}
				c++;
			}
			else{
				if (sb.top() < k){
					sb.push(k);
				}
				else if (sc.top() < k){
					sc.push(k);
				}
				else{
					f = 0;
				}
			}
		}
		if (f){
			cout << "YES\n";
		}
		else{
			cout << "NO\n";
		}
	}
}

C++: 
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <stack>
#include <cctype>
#include <complex>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <cassert>

using namespace std;


bool solve(){
	int a = 0, b = 0;
	int in;
	int ans = 1;
	for(int i=0;i<10;i++){
		cin>> in;
		if(b < in){
			b = in;
		}else if(a < in){
			a = in;
		}else{
			ans = 0;
			for(int j=i+1;j<10;j++){
				cin>> in;
			}
			break;
		}
		if(a > b) swap(a,b);
	}
	string str = ans ? "YES" : "NO";
	cout<< str << endl;
	return true;
}

int main(){
	cout.setf(ios::fixed);
	cout.precision(10);
	int n;
	cin>> n;
	for(int i=0;i<n;i++){
		solve();
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int a=0,b=0;
  int c=0;
  cin>>c;
  for(int i=0;i<c;i++){
    a=0;
    b=0;
    for(int i=0;i<10;i++){
      int t=0;
      cin>>t;
      if(t==0)break;
      if(t<a&&t<b){
	cout<<"NO"<<endl;
	break;
      }
      if(a<t)a=t;
      else b=t;
      if(i==9)cout<<"YES"<<endl;
    }
  }
  return 0;
}

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

int main() {
	int n, x, z;
	cin >> n;

	for (int i = 0; i < n; i++) {
		vector< vector<int> > v = { vector<int>{0} };
		for (int j = 0; j < 10; j++) {
			cin >> x;
			z = v.size();
			for (int k = 0; k < z; k++) {
				if (v[k].back() < x) {
					v[k].push_back(x);
					break;
				}

				if (k == z - 1) {
					v.push_back(vector<int> { x });
					break;
				}
			}

			if (v.size() == 3) {
				x = -1;
				break;
			}
		}

		if (x == -1) {
			cout << "NO";
		}
		else {
			cout << "YES";
		}
		cout << endl;
	}
	return 0;
}

C++: #include <iostream>

int main(){
  int n;
  std::cin >> n;
  while(n--){
    int b = 0;
    int c = 0;
    for(int i=0; i<10; i++){
      int t;
      std::cin >> t;
      if(b < t)       b = t;
      else if(c < t)  c = t;
      else{
        std::cout << "NO" << std::endl;
        break;
      }
      if(i == 9)  std::cout  << "YES" << std::endl;
    }
  }
}

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

int ball[1001][10];
//int end[2][10];

bool dfs(int i, int j, int left_max, int right_max) {
	if (j == 10) return true;
	
	if (left_max < ball[i][j]) return dfs(i, j + 1, ball[i][j], right_max);
	else if (right_max < ball[i][j]) return dfs(i, j + 1, left_max, ball[i][j]);
	
	return false;
}

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

C++: #include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
const double EPS = 1e-10;
const double PI  = acos(-1.0);

bool dfs(vi &a, int pos,int l,int r){
	if(pos==10){
		return true;
	}
	REP(i,2){
		if(i==0&&a[pos]>l&&dfs(a,pos+1,a[pos],r)){
			return true;
		}
		if(i==1&&a[pos]>r&&dfs(a,pos+1,l,a[pos])){
			return true;
		}
	}
	return false;
}

int main(){
	int n;
	cin>>n;
	REP(i,n){
		vi a(10);
		REP(i,10){
			cin>>a[i];
		}
		cout<<(dfs(a,0,0,0)?"YES":"NO")<<endl;
	}
}