/*
TASK:seq
LANG:C++
*/

#include<stdio.h>

int set[131072], M;
int pos;
bool rec(int m1, int m2) {
	if(pos == M) return true;
	++pos;
	if(m1 < set[pos-1]) {
		if(rec(set[pos-1], m2)) return true;
	}
	if(m2 < set[pos-1]) {
		if(rec(m1, set[pos-1])) return true;
	}
	--pos;
	return false;
}

int main() {
	int n;
	scanf("%d", &n);
	for(int i = 0; i < n; ++i) {
		scanf("%d", &M);
		if(M == 1) {
			printf("0");
			continue;
		} else if(M == 2) {
			printf("1");
			continue;
		}
		for(int j = 0; j < M; ++j) {
			scanf("%d", set+j);
		}
		pos = 0;
		printf("%i", (int)rec(0, 0));
	}
	return 0;
}
