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

?¢???????????§??????????????????¢???????§???§?\?????????????A??£?????\???????????????????????????????????????DE?????¶??????B?£???????C?£??????????
??°??????1-10??????????????????????????????A??£?????\???????????????????§???§??¶??????????????\?????\???B?£???????C?£???????????????????????????????????¢????

?????\????¬¬???????????\??°????????°N?????\?????\N??????N???????????°??????????????°?????????10?????´??°?????£??¨???????????\?????????

???????????????????????°????????\?????\?????¨?????????YES?????\????????¨?????????NO
 */
#include <assert.h>
#include <ctype.h>
#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>

#include <algorithm>
#include <complex>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define SZ(a) (int)(a).size()
#define FOR(i,a,b) for (int i=(a); i<=(b); ++i)
#define REP(i,n) for (int i=0; i<(n); ++i)
#define ALL(c) c.begin(), c.end()
#define CLR(c,n) memset(c, n, sizeof(c))
#define TR(it, c) for(typeof(c.begin()) it = c.begin();it != c.end(); ++it)
#define CONTAIN(it, c) (c.find(it) != c.end())
typedef vector<int> VI;
typedef pair<int, int> PII;
template <class T> void checkmin(T &a, T b) { if (b<a) a=b; }
template <class T> void checkmax(T &a, T b) { if (b>a) a=b; }

int main(int argc, char *argv[]) {
  int n, x;
  for (scanf("%d", &n); n; --n) {
    int l1 = 0, l2 = 0;
    bool ret = true;
    REP(i, 10) {
      scanf("%d", &x);
      if (x > l2) l2 = x;
      else if (x > l1) {
        l1 = x;
      } else {
        ret = false;
      }
    }
    puts(ret? "YES" : "NO");
  }
}

C++: // AOJ 0033
#include<cstdio>
#define rep( i, a ) for( int i = 0; i != (a); ++i )

int main()
{
	int N;
	scanf( "%d", &N );

	rep( i, N )
	{
		int l = 0, r = 0;
		bool fl = true;

		rep( j, 10 )
		{
			int a;
			scanf( "%d", &a );

			if( a > l && a > r )
			{
				if( l > r )
					l = a;
				else
					r = a;
			}
			else if( a > l )
				l = a;
			else if( a > r )
				r = a;
			else
				fl = false;
		}

		puts( fl ? "YES" : "NO" );
	}

	return 0;
}

C++: // scnucjh
// AOJ 0033
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int n;
vector<int> B,C;
int A[10];
bool flag; //是否有解

void dfs(int x) {
	if(x==10) { //球丢完了，递归要返回
		for(int i=1;i<B.size();i++) {
			if(B[i]<B[i-1]) return; //这个分支不行,有矛盾
		}
		for(int i=1;i<C.size();i++) {
			if(C[i]<C[i-1]) return; //这个分支不行,有矛盾
		}
		flag = true; 			 //这个分支走到最后是有解的
		return;
	}
	B.push_back(A[x]); 			//把第x个球丢给B
	dfs(x+1);  					//进入这个分支
	B.pop_back(); 				//撤销操作，弹出B的最后一个球
	
	C.push_back(A[x]); 			//把第x个球丢给C
	dfs(x+1);    				//进入这个分支
	C.pop_back(); 				//撤销操作，弹出C的最后一个球
}

int main() {
	int T;
    scanf("%d",&T);
	while(T--) {
		for(int i=0;i<10;i++) scanf("%d",&A[i]);
		flag = false;
		dfs(0);
		puts(flag ? "YES":"NO");
	}
    return 0;
}

C++: #include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <bitset>

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++: #include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>
using namespace std;
int main(){
	int N;
	cin>>N;
	for(int i=0;i<N;i++){
		int a[9]={};
		int b[9]={};
		int dat,o=0,s=0;
		for(int j=0;j<=10;j++){
			if(j==10){
				cout<<"YES"<<endl;
				break;
						}
			cin>>dat;
		 	if(j==0){
				a[0]=dat;
				s++;
				o++;
			}
			if(dat>a[s-1]){
				a[s]=dat;
				s++;
			}
			else if(dat>b[o-1]){
				b[o]=dat;
				o++;}
			else{
				cout<<"NO"<<endl;
			break;
			}
					}
	}
	return 0;
}

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

vector<int> data;
vector<int> tube_B;
vector<int> tube_C;

const int MAX = 10;

int dfs(int count){
    
    if (count == MAX) return 1;

    int ret = 0;

    int b = tube_B.size() - 1;
    int c = tube_C.size() - 1;

    if (data[count] > tube_B[b]){
        tube_B.push_back(data[count]);
        ret = max(ret, dfs(count + 1));
        tube_B.pop_back();
    }

    if (data[count] > tube_C[c]){
        tube_C.push_back(data[count]);
        ret = max(ret, dfs(count + 1));
        tube_C.pop_back();
    }

    return ret;
}

int main(void){

    int n;
    cin >> n;
    tube_B.push_back(-1);
    tube_C.push_back(-1);

    for (int i = 0; i < n; i++){
        for (int j = 0; j < 10; j++){
            int s;
            cin >> s;
            data.push_back(s);
        }

        int s = dfs(0);

        if (s == 1){
            cout << "Yes" << endl;
        }
        else{
            cout << "No" << endl;
        }

        data.erase(data.begin(), data.end());
        tube_B.erase(tube_B.begin(), tube_B.end());
        tube_C.erase(tube_C.begin(), tube_C.end());
    }




}

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

int main()
{
	queue<int> a;  // ?????£??¨
	int n;
	int ball = 10;
	cin>>n;
	while( n-- > 0){
		int b=0, c=0;
		int k;
		for(int i=0;i<ball;i++){
			cin>>k;
			a.push( k );
		}
		
		// ??????????????????b?????\????????????
		b = a.front();
		a.pop();
		
		for(int i=0;i<ball-1;i++){
			if( a.front() > b && a.front() > c){
				if( a.front() - b > a.front() - c){
					c = a.front();
				}else{
					b = a.front();
				}
			}else if( a.front() > b){
				b = a.front();
			}else if( a.front() > c){
				c = a.front();
			}else{  // ?????????????????????
				cout<<"NO"<<endl;
				while(1){
					if( a.empty()){
						break;
					}else{
						a.pop();
					}
				}
				break;
			}
			
			a.pop();
			if( a.empty()){
				cout<<"YES"<<endl;
				while(1){
					if( a.empty()){
						break;
					}else{
						a.pop();
					}
				}
			}
		}
	}
	return 0;
}

C++: #include<cstdio>
#include<iostream>
using namespace std;
#define rep(x,y) for(x=0;x<(y);++x)
void in();
void solve();
int bod[14];
int main()
{
	int t;
	cin>>t;
	int ti;
	rep(ti,t)
	{
		in();
		solve();
	} 
	return 0;
}
void in()
{
	int i;
	rep(i,10)
	{
		cin>>bod[i];
	}
}
void solve()
{
	int l=0,r=0,u;
	int le[11],ri[11];
	for(u=0;u<10;++u)
	{
		if(0==l)
		{
			le[0]=bod[u];
			++l;
		}
		else if(bod[u]>le[l-1])
		{
			le[l]=bod[u];
			++l;
		}
		else if(0==r||bod[u]>ri[r-1])
		{
			ri[r]=bod[u];
			++r;
		}
		else
		{
			cout<<"NO\n";
			return;
		}
	}
	cout<<"YES\n";
}