n = gets.to_i
n.times {
    a = gets.split.map(&:to_i)
    x = y = 0
    ok = true
    a.each{|z|
        if z < [x, y].min
            ok = false
            break
        end

        if z > [x, y].max
            x, y = [x, y].min, z
        else
            x, y = [x, y].max, z
        end
    }
    puts ok ? "YES" : "NO"
}