n=gets.to_i
arr=Array.new
for i in 1..n
   ball=gets.split(" ").map(&:to_i)
   
   left,right=Array.new,Array.new
   left[0],right[0]=ball[0],0
   l,r=0,0
   frag=0
   for j in 0..8
      if ball[j+1]>left[l]
         left[l+1]=ball[j+1]
         l+=1
      elsif ball[j+1]>right[r]
         right[r+1]=ball[j+1]
         r+=1
      else ball[j+1]<left[l] and ball[j+1]<right[r]
         puts "NO"
         frag=1
         break 
      end
   end
   puts "YES" if frag==0
end