n = gets.to_i
n.times{
    arr = gets.chomp.split.map(&:to_i)
    order = nil
    0.upto(2**10 - 1){|i|
        order = true
        arr2 = [[], []]
        sprintf("%010b", i).split("").map(&:to_i).each_with_index{|x, j|
            arr2[x] << arr[j]
            if arr2[x].length > 1 && arr2[x][-2] > arr2[x][-1]
                order = false
                break
            end
        }
        break if order
    }
    puts order ? "YES" : "NO"
}
