read_line.to_i.times do puts solve() ? "Yes" : "No" end def solve n = read_line.to_i a = read_line.split.map(&.to_i) b = read_line.split.map(&.to_i) c = Array.new(n, 0) st = [0] n.times do |i| if a[i] > b[i] return false end st << a[i] if a[i] > st[-1] while st[-1] > b[i] st.pop end c[i] = st[-1] end st = [0] (n - 1).downto(0) do |i| st << a[i] if a[i] > st[-1] while st[-1] > b[i] st.pop end c[i] = {c[i], st[-1]}.max end return b == c end