#include<stdio.h>
int main(void)
{
	int n,i,sum,t,aaa,bbb,nnn;
	char ch,a[10000];
	scanf("%d",&n);
	getchar();
	while(n--)
	{
		t=0;i=0;
		sum=0;aaa=0;bbb=0;
		while((ch=getchar())!='\n')
			a[i++]=ch;
		nnn=i;
		for(i=0;i<nnn;i++)
		{
			if(a[i]>='1'&&a[i]<='9')
			{
				if(a[i+1]=='0')
					sum=10,i++;
				else
					sum=a[i]-'0';
				if(aaa==0)
					aaa=sum;
				else
				{
					if(aaa<sum&&bbb<sum)
						t=1;
					if(aaa>sum)
						bbb=sum;
					else
					{
						if(bbb>sum)
							aaa=sum;
						else
						{
							if(aaa>bbb)
								aaa=sum;
							else
								bbb=sum;
						}
					 } 
				}
			}
			
		}
		if(t==1)
			printf("YES\n");
		else
			printf("NO\n");
	}
}
