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, 9) {
      int a = nextInt();
      if (bs.top() == cs.top()) {
        if (bs.top() > a) {
          flag = false;
          break;
        }
        bs.push(a);
      } else if (bs.top() > cs.top()) {
        if (bs.top() > a) {
          if (cs.top() > a) {
            flag = false;
            break;
          }
          cs.push(a);
        } else {
          bs.push(a);
        }
      } else {
        if (cs.top() > a) {
          if (bs.top() > a) {
            flag = false;
            break;
          }
          bs.push(a);
        } else {
          cs.push(a);
        }
      }
    }
    if (flag) {
      PRINT("YES");
    } else {
      PRINT("NO");
    }
  }
	return 0;
}
// END   //////////////////////////////////////////////////////////////

C++: #include <stdio.h>

int main(void) {
  int i, j, k, n, a[10];
  scanf("%d", &n);
  for(i = 0; i < n; ++i) {
    for(j = 0; j < 10; ++j) scanf("%d", &a[j]);
    int bea = 0, beb = -1, ans = 1;
    for(j = 0; j < 10; ++j) {
      if(bea > beb) {
        if(bea < a[j]) bea = a[j];
        else if(beb < a[j]) beb = a[j];
        else {
          ans = 0;
          break;
        }
      } else {
        if(beb < a[j]) beb = a[j];
        else if(bea < a[j]) bea = a[j];
        else {
          ans = 0;
          break;
        }
      }
    }
    if(ans) printf("YES\n");
    else printf("NO\n");
  }
  return 0;
}

C++: #include <iostream>
#include <stack>
using namespace std;
int a[10];
stack<int> b[2];
bool dfs(int i, int to)
{
	if (i == 9)
	{
		if (a[i] > b[to].top() || a[i] > b[!to].top())
			return true;
		else
			return false;
	}
	else if (a[i] > b[to].top() && a[i] > b[!to].top())
	{
		b[to].push(a[i]);
		if (dfs(i+1, to))
			return true;
		b[to].pop();
		b[!to].push(a[i]);
		if (dfs(i+1, !to))
			return true;
		return false;
	}
	else if (a[i] > b[to].top())
	{
		b[to].push(a[i]);
		if (dfs(i+1, to))
			return true;
		b[to].pop();
		return false;
	}
	else if (a[i] > b[!to].top())
	{
		b[!to].push(a[i]);
		if (dfs(i+1, !to))
			return true;
		b[!to].pop();
		return false;
	}
	else
		return false;
}
int main()
{
	int n, i, j;
	cin >> n;
	for (i = 0; i < n; i++)
	{
		for (j = 0; j < 10; j++)
			cin >> a[j];
		b[0].push(0);
		b[1].push(0);
		if (dfs(0, 0)) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
}

C++: #include <iostream>

int main(void)
{
	int n;
	std::cin >> n;
	for(int j=0; j<n; j++)
	{
		int top[2]={0,0};
		for(int i=0; ; i++)
		{
			std::cout << top[0] << top[1] << std::endl;
			int next;
			std::cin >> next;
			if((top[0] < next)&&(top[1] < next))
			{
				if(top[0] < top[1])
					top[1]=next;
				else
					top[0]=next;
			}
			else if(top[0] < next)
				top[0]=next;
			else if(top[1] < next)
				top[1]=next;
			else
			{
				std::cout << "NO" << std::endl;
				for(int k=1; k+i < 10; k++)
					std::cin >>next;
				break;
			}

			if(i==9)
			{
				std::cout << "YES" << std::endl;
				break;
			}
		}
	}
	return 0;
}

C++: #include <stdio.h>

int main(void)
{
	int data[10];
	int n;
	int a, b;
	int j;
	
	scanf("%d", &n);
	
	a = b = 0;
	for (int i = 0; i < n; i++){
		for (int j = 0; j < 10; j++){
			scanf("%d", &data[j]);
		}
		for (j = 0; j < 10; j++){
			if (a < data[j]){
				a = data[j];
			}
			else if (b < data[j]){
				b = data[j];
			}
			else {
				break;
			}
		}
		
		if (j == 10){
			puts("YES");
		}
		else {
			puts("NO");
		}
	}
	
	return (0);
}

C++: #include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <list>

using namespace std;

int main(int, char**){
    int n;
    cin >> n;
    //vector<int> vec;
    int vec[10];
    for(int as(0);as<n;++as){
	for(int i(0);i<10;++i){
	    int tmp;
	    cin >> tmp;
	    vec[i] = tmp;
	}
	int a(0),b(0);
	for(int i(0);i<10;++i){
	    if(vec[i]<min(a,b)){
		cout << "NO" << endl;
     		goto hai;
     	    }
	    if(a>b) swap(a,b);
	    if(b>vec[i]) a = vec[i];
	    else b = vec[i];
	}
	cout << "YES" << endl;
	hai:;
    }
    //string tmp;
    
    // while(getline(cin,tmp)){
    // 	istringstream is(tmp);
    // 	int m;
    // 	list<int> vec;
    // 	while(is >> m) vec.push_back(m);
    // 	int a(0),b(0);
    // 	for(auto it=begin(vec);it!=end(vec);++it){
    // 	    if(*it>min(a,b)){
    // 		
    // 	    if(a>b){ swap(a,b);}
    // 	    b = *it;
    // 	}
    // 	cout << "YES" <<endl;
    // hai:;
    // 	vec.clear();
    // }
    return 0;
}

C++: #include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
    return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

bool solve(const auto& balls) {
    const int n = balls.size();
    stack<int> l, r;
    
    function<bool(int)> rec = [&](int i) {
        if (i == n) return true;

        bool pro = false;
        if (l.empty() || l.top() < balls[i]) { // left push
            l.push(balls[i]);
            pro = pro || rec(i + 1);
            l.pop();
        } 

        if (r.empty() || r.top() < balls[i]) { // right push
            r.push(balls[i]);
            pro = pro || rec(i + 1);
            r.pop();
        }

        return pro;
    };

    return rec(0);
}

int main() {
    constexpr int BALLS = 10;
    int n; cin >> n;
    REP(i, n) {
        vector<int> b(BALLS);
        REP(j, BALLS) cin >> b[j];

        if (solve(b)) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }
    return 0;
}