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++: // Aoj 0033: Ball
#include<bits/stdc++.h>
#define mset(x,y) memset(x,y,sizeof(x))
using namespace std;

const int N=110,M=20010;
int h[N],to[M],nexp[M],p=1;
inline void init_list(){mset(h,0),mset(nexp,0),p=1;}
inline void ins(int a,int b){
    nexp[p]=h[a],h[a]=p,to[p]=b,p++;
}
int arr[N];
int col[N];
bool imp;
void dfs(int x,int ncol){
    col[x]=ncol;
    for(int u=h[x];u;u=nexp[u]){
        if(col[to[u]] == col[x]) imp=1;
        if(imp) return;
        if(!col[to[u]]) dfs(to[u],ncol^1);
    }
}

int main(){
    ios::sync_with_stdio(false);
    int t;
    cin>>t;
    while(t--){
        for(int i=0;i<10;i++) cin>>arr[i];
        init_list();
        for(int i=0;i<10;i++)
        for(int j=i+1;j<10;j++)
            if(arr[i]>arr[j]) ins(i,j),ins(j,i);
        mset(col,0), imp=0;
        for(int i=0;i<10;i++)
            if(!col[i]) dfs(i,2);
        if(imp) cout<<"NO"<<endl;
        else cout<<"YES"<<endl;
    }
    return 0;
}

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

#define iota(i,n,b,s) for(int i=int(b);i!=int((b)+(s)*(n));i+=(s))
#define range(i,n,m) iota(i,(((n)>(m))?((n)-(m)):((m)-(n))),(n),((n)>(m)?-1:1))
#define rep(i,n) iota(i,(n),0,1)
#define loop for(;;)

#define INF (1e9)
#define EPS (1e-9)
#define cons(a,b) (make_pair(a,b))
#define car(a) (a.first)
#define cdr(a) (a.second)
#define cadr(a) (car(cdr(a)))
#define cddr(a) (cdr(cdr(a)))
#define all(a) a.begin(), a.end()
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;

typedef long long Integer;
typedef double Real;
typedef vector<int> vi;
typedef vector<string> vs;
typedef map<string,int> Dictionary;
const Real PI = acos(-1);

template<class S, class T>
ostream& operator<<(ostream& os, pair<S,T> p) {
  os << '(' << car(p) << ", " << cdr(p) << ')';
  return os;
}

template<class T>
ostream& operator<<(ostream& os, vector<T> v) {
  if (v.size() == 0) {
    os << "(empty)";
    return os;
  }
  os << v[0];
  for (int i=1, len=v.size(); i<len; ++i) os << ' ' << v[i];
  return os;
}

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

bool
f(vector<int>&ln, int idx, int x, int y) {
  if (idx == 10) return true;
  int z = ln[idx];
  return (x < z && f(ln, idx + 1, z, y)) || (y < z && f(ln, idx + 1, x, z));
}

int main() {

  int n; cin >> n;
  for (;n--;) {
    vector<int> ln(10);
    rep (i, 10) cin >> ln[i];
    bool bl = f(ln, 0, 0, 0);
    cout << (bl ? "YES" : "NO" ) <<endl;
  }

  return 0;
}

C++: //#define LOCAL 

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>

#define SIZE 10

using namespace std;

int map[SIZE];

bool dfs(int a, int b, int pos){
	//printf("a: %d b: %d pos: %d\n", a, b, pos);

	if(pos == SIZE)
		return true;

	if(map[pos] > a)
		return dfs(map[pos], b, pos + 1);

	if(map[pos] > b)
		return dfs(a, map[pos], pos + 1);

	return false;
}

int main(void){
#ifdef LOCAL
	freopen("data.in", "r", stdin);
#endif 
	int n;
	
	scanf("%d", &n);
	while(n--){
		for(int i = 0; i < SIZE; i++){
			scanf("%d", &map[i]);
	//		printf("%d ", map[i]);
		}
	//	printf("\n");

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

	return 0;
}

C++: #include <cstdio>

int a[10];


int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    bool ans = true;
    for (int i = 0; i < 10; ++i) {
      scanf("%d", &a[i]);
    }
    int l, r;
    l = r = 0;
    for (int i = 0; i < 10; ++i) {
      if (a[i] > l) {
        l = a[i];
      } else if (a[i] > r) {
        r = a[i];
      } else {
        ans = false;
        break;
      }
    }
    printf("%s\n", ans ? "YES" : "NO");
  }
  return 0;
}

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

int main() {
	int n; cin >> n;
	for (int i = 0; i < n; i++) {
		int b[10];
		int left = 0, right = 0;
		bool avail = true;
		for (int j = 0; j < 10; j++)
			cin >> b[j];
		for (int j = 0; j < 10; j++) {
			if (b[j] > left) left = b[j];
			else if (b[j] > right) right = b[j];
			else avail = false;
		}
		cout << (avail ? "YES" : "NO") << endl;
	}
	return 0;
}

C++: Public class Main {
	void run() {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] boll = new int[10];
		for(int k = 0; k < n; k++) {
			for(int i = 0; i < 10; i++) {
				boll[i] = scan.nextInt();
			}
			int judg = 0;
			for(int i = 0; i < n; i++) {
				int right,left;
				right = boll[0];
				left = 0;
				for(int m = 1; m < 10; m++) {
					if(right > boll[m]) {
						if(left < boll[m]) {
							left = boll[m];
						}
						else {
							judg = 0;
							break;
						}
					}
					else if(right < boll[m]) {
						right = boll[m];
					}
					judg = 1;
				}
				if(judg == 0) {
					System.out.println("NO");
				}
				else {
					System.out.println("YES");
				}
			}
		}
	}
	public static void main(String[] args) {
		new Main().run();
	}
}

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--){
        queue<int>que;
        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";
                return 0;
            }
            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;
            }
        }
        cout<<"YES\n";
    }

    return 0;
}

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

bool f(void){
	int a=0, b=0, e;
	for (int i=0; i<10; i++){
		cin>>e;
		if (e>a) a=e;
		else if (e>b) b=e;
		else return false;
	}
	return true;
}

int main(void){

	int n;

	cin>>n;
	while (n--){
		if (f()) cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

int main(void) {
    int N, a, b, c, x[10];
    cin >> N;
    for (; N--; ) {
        bool ok = true;
        b = c = 0;
        for (int i = 0; i < 10; i++) {
            cin >> x[i];
            a = x[i];
            if (a < b && a < c) {
                ok = false;
                break;
            } else if (a < b) {
                c = a;
            } else if (a < c) {
                b = a;
            } else if (b < c) {
                c = a;
            } else {
                b = a;
            }
        }
        if (ok) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    return 0;
}

C++: #define _USE_MATH_DEFINES

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <utility>
#include <vector>
#include <numeric>

using namespace std;

int main()
{
	int n;
	for (cin >> n; n--;)
	{
		vector<int> b;
		vector<int> c;

		for (int i = 0; i < 10; i++)
		{
			int x;
			cin >> x;

			if (i == 0)
			{
				b.push_back(x);
			}
			else if (i == 1)
			{
				c.push_back(x);
			}
			else
			{
				if (x > b.back() || x > c.back())
				{
					if (b.back() > c.back())
					{
						b.push_back(x);
					}
					else
					{
						c.push_back(x);
					}
				}
			}
		}

		cout << (b.size() + c.size() == 10 ? "YES" : "NO") << endl;
	}
}