def solve
  n, u, r, d, l = ints
  (1 << 4).times.any? do |bits|
    lu, ru, ld, rd = (0 ... 4).map { |i| bits[i] == 1 }
    l_use = r_use = u_use = d_use = 0
    if lu
      l_use += 1
      u_use += 1
    end
    if ru
      r_use += 1
      u_use += 1
    end
    if ld
      l_use += 1
      d_use += 1
    end
    if rd
      r_use += 1
      d_use += 1
    end
    [l - l_use, r - r_use, u - u_use, d - d_use].all? { |x| 0 <= x and x <= n - 2}
  end
end

def main
  t = int
  t.times do
    yesno solve
  end
end

DEBUG = true
MOD = 10**9+7
YESNO = %w(NO YES)
INF = 10**9

def int; gets.to_s.to_i end
def ints; gets.to_s.split.map { |s| s.to_i } end
def int1s; gets.to_s.split.map { |s| s.to_i - 1 } end
def float; gets.to_s.to_f end
def floats; gets.to_s.split.map { |s| s.to_f } end
def array_of(&convert); gets.to_s.split.map(&convert) end
def string; gets.to_s.chomp end
def rep(n, &b); Array.new(n, &b) end
def yes; puts YESNO[1] end
def no; puts YESNO[0] end
def yesno t; puts YESNO[t] end
def zip(xs, *yss); Enumerator.new { |y| xs.zip(*yss) { |a| y.yield(*a) } } end
def max(*xs, &block); block_given? ? xs.max_by(&block) : xs.max end
def min(*xs, &block); block_given? ? xs.min_by(&block) : xs.min end
def minmax(*xs, &block); block_given? ? xs.minmax_by(&block) : xs.minmax end
def gcd(*xs); xs.inject(0, :gcd) end
def matrix(h, w, fill=nil, &block); return Array.new(h) { Array.new(w, &block) } if block_given?; Array.new(h) { [fill] * w } end
def debug(x = nil); STDERR.puts (block_given? ? yield(x) : x).inspect if DEBUG; x end
def debug_grid(grid, width = 1); grid.each { |row| STDERR.puts row.map { |x| x.inspect.ljust(width) }.join("") } if DEBUG; grid end
def if_debug; yield if DEBUG end

module Boolean
  def coerce(other); [other, to_i] end
  def +@; to_i end
  def to_int; to_i end
  def *(other); to_i * other end
end

class TrueClass
  include Boolean
  def to_i; 1 end
end

class FalseClass
  include Boolean
  def to_i; 0 end
end

class Integer
  def div_ceil(y); (self + y - 1) / y end
  def mod_inv(mod = MOD); pow(mod-2, mod) end
  def mod_div(y, mod = MOD); self * mod_inv(y, mod) % mod end
  def factorial(mod = MOD); (2..self).inject(1) { |f, x| f * x % mod } end
  def popcount; x = self; c = 0; while x > 0; c += 1 if x & 1 == 1; x >>= 1 end; c end #TODO: faster
  def bitbrute(&block); (1<<self).times(&block) end
  def nCr(r); x = 1; (1..r).each { |i| x *= self + 1 - i; x /= i }; x; end
  def each_divisor; return Enumerator.new { |y| each_divisor { |k| y << k } } unless block_given?; k = 1; while k * k < self; if self % k == 0; yield k; yield self / k end; k += 1; end; yield k if k * k == self end
  def divisors; each_divisor.to_a end
end

class Range
  def end_open; exclude_end? ? self.end : self.end + 1 end
  def end_close; exclude_end? ? self.end - 1 : self.end end
  def upper_bound; ac, wa = self.begin, self.end_open; while wa - ac > 1; if yield((wj = (ac + wa) / 2)); ac = wj else wa = wj end; end; yield(ac) ? ac : nil end
  def lower_bound; ac, wa = self.end_open, self.begin; while ac - wa > 1; if yield((wj = (ac + wa) / 2)); ac = wj else wa = wj end; end; yield(ac) ? ac : nil end
  def shakutori(r2, &pred); Enumerator.new { |y| j, r = r2.begin, r2.end_open; each { |i| j += 1 while j + 1 < r and pred[i, j+1]; y.yield(i, j) } }; end
  def widest(&block); Enumerator.new { |y| j, n = self.begin, self.end_open; each { |i| j += 1 while j < n and block[i, j]; y.yield(i, j) if block[i, j] } } end
end

class Array
  def power(&block); (0 ... 1 << size).each(&block) end
  def sorted_merge(other); a = []; i = j = 0; n, m = size, other.size; if j < m and other[j] < self[i]; a << other[j]; j += 1 else; a << self[i]; i += 1 end while i < n; a.push(*other[j..-1]) if j < m; a end
  def upper_bound; ac, wa = 0, size; while wa - ac > 1; if yield(self[(wj = (ac + wa) / 2)]); ac = wj else; wa = wj end; end; ac end
  def lower_bound; ac, wa = size, 0; while wa - ac > 1; if yield(self[(wj = (ac + wa) / 2)]); ac = wj else; wa = wj end; end; ac end
  def cum(*xs, &op); a = []; a << xs[0] if xs.size > 0; a << x = self[0]; (1...size).each { |i| a << x = op[x, self[i]] }; a end
  def cumdiff(range); self[range.end_open] - self[range.begin]; end
end

module Enumerable
  def sorted_uniq; x = nil; filter { |y| c = x === y; x = y; !c } end
  def cumsum; ys = [0]; each { |x| ys << x + ys[-1] }; ys end
end

main

gets.to_i.times do
    n, u, r, d, l = gets.split.map &:to_i
    ok = false
    16.times do |msk|
        cu, cr, cd, cl = u, r, d, l
        if msk & 1 > 0
            cu -= 1
            cl -= 1
        end
        if msk & 2 > 0
            cl -= 1
            cd -= 1
        end
        if msk & 4 > 0
            cd -= 1
            cr -= 1
        end
        if msk & 8 > 0
            cr -= 1
            cu -= 1
        end
        if [cu, cr, cd, cl].min >= 0 && [cu, cr, cd, cl].max <= n - 2
            puts "YES"
            ok = true
            break
        end
    end
    puts "NO" if !ok
end

def solve
  n, u, r, d, l = ints
  (1 << 4).times.any? do |bits|
    lu, ru, ld, rd = (0 ... 4).map { |i| bits[i] == 1 }
    l_use = r_use = u_use = d_use = 0
    if lu
      l_use += 1
      u_use += 1
    end
    if ru
      r_use += 1
      u_use += 1
    end
    if ld
      l_use += 1
      d_use += 1
    end
    if rd
      r_use += 1
      d_use += 1
    end
    possible = (l_use <= l and r_use <= r and u_use <= u and d_use <= d)
    possible &&= lu ? (l >= 1 and u >= 1) : (l <= n - 1 and u <= n - 1)
    possible &&= ru ? (r >= 1 and u >= 1) : (r <= n - 1 and u <= n - 1)
    possible &&= ld ? (l >= 1 and d >= 1) : (l <= n - 1 and d <= n - 1)
    possible &&= rd ? (r >= 1 and d >= 1) : (r <= n - 1 and d <= n - 1)
    possible &&= (lu and ru) ? (u >= 2) : true
    possible &&= (lu and ld) ? (l >= 2) : true
    possible &&= (ru and rd) ? (r >= 2) : true
    possible &&= (ld and rd) ? (d >= 2) : true
    possible
  end
end

def main
  t = int
  t.times do
    yesno solve
  end
end

DEBUG = true
MOD = 10**9+7
YESNO = %w(NO YES)
INF = 10**9

def int; gets.to_s.to_i end
def ints; gets.to_s.split.map { |s| s.to_i } end
def int1s; gets.to_s.split.map { |s| s.to_i - 1 } end
def float; gets.to_s.to_f end
def floats; gets.to_s.split.map { |s| s.to_f } end
def array_of(&convert); gets.to_s.split.map(&convert) end
def string; gets.to_s.chomp end
def rep(n, &b); Array.new(n, &b) end
def yes; puts YESNO[1] end
def no; puts YESNO[0] end
def yesno t; puts YESNO[t] end
def zip(xs, *yss); Enumerator.new { |y| xs.zip(*yss) { |a| y.yield(*a) } } end
def max(*xs, &block); block_given? ? xs.max_by(&block) : xs.max end
def min(*xs, &block); block_given? ? xs.min_by(&block) : xs.min end
def minmax(*xs, &block); block_given? ? xs.minmax_by(&block) : xs.minmax end
def gcd(*xs); xs.inject(0, :gcd) end
def matrix(h, w, fill=nil, &block); return Array.new(h) { Array.new(w, &block) } if block_given?; Array.new(h) { [fill] * w } end
def debug(x = nil); STDERR.puts (block_given? ? yield(x) : x).inspect if DEBUG; x end
def debug_grid(grid, width = 1); grid.each { |row| STDERR.puts row.map { |x| x.inspect.ljust(width) }.join("") } if DEBUG; grid end
def if_debug; yield if DEBUG end

module Boolean
  def coerce(other); [other, to_i] end
  def +@; to_i end
  def to_int; to_i end
  def *(other); to_i * other end
end

class TrueClass
  include Boolean
  def to_i; 1 end
end

class FalseClass
  include Boolean
  def to_i; 0 end
end

class Integer
  def div_ceil(y); (self + y - 1) / y end
  def mod_inv(mod = MOD); pow(mod-2, mod) end
  def mod_div(y, mod = MOD); self * mod_inv(y, mod) % mod end
  def factorial(mod = MOD); (2..self).inject(1) { |f, x| f * x % mod } end
  def popcount; x = self; c = 0; while x > 0; c += 1 if x & 1 == 1; x >>= 1 end; c end #TODO: faster
  def bitbrute(&block); (1<<self).times(&block) end
  def nCr(r); x = 1; (1..r).each { |i| x *= self + 1 - i; x /= i }; x; end
  def each_divisor; return Enumerator.new { |y| each_divisor { |k| y << k } } unless block_given?; k = 1; while k * k < self; if self % k == 0; yield k; yield self / k end; k += 1; end; yield k if k * k == self end
  def divisors; each_divisor.to_a end
end

class Range
  def end_open; exclude_end? ? self.end : self.end + 1 end
  def end_close; exclude_end? ? self.end - 1 : self.end end
  def upper_bound; ac, wa = self.begin, self.end_open; while wa - ac > 1; if yield((wj = (ac + wa) / 2)); ac = wj else wa = wj end; end; yield(ac) ? ac : nil end
  def lower_bound; ac, wa = self.end_open, self.begin; while ac - wa > 1; if yield((wj = (ac + wa) / 2)); ac = wj else wa = wj end; end; yield(ac) ? ac : nil end
  def shakutori(r2, &pred); Enumerator.new { |y| j, r = r2.begin, r2.end_open; each { |i| j += 1 while j + 1 < r and pred[i, j+1]; y.yield(i, j) } }; end
  def widest(&block); Enumerator.new { |y| j, n = self.begin, self.end_open; each { |i| j += 1 while j < n and block[i, j]; y.yield(i, j) if block[i, j] } } end
end

class Array
  def power(&block); (0 ... 1 << size).each(&block) end
  def sorted_merge(other); a = []; i = j = 0; n, m = size, other.size; if j < m and other[j] < self[i]; a << other[j]; j += 1 else; a << self[i]; i += 1 end while i < n; a.push(*other[j..-1]) if j < m; a end
  def upper_bound; ac, wa = 0, size; while wa - ac > 1; if yield(self[(wj = (ac + wa) / 2)]); ac = wj else; wa = wj end; end; ac end
  def lower_bound; ac, wa = size, 0; while wa - ac > 1; if yield(self[(wj = (ac + wa) / 2)]); ac = wj else; wa = wj end; end; ac end
  def cum(*xs, &op); a = []; a << xs[0] if xs.size > 0; a << x = self[0]; (1...size).each { |i| a << x = op[x, self[i]] }; a end
  def cumdiff(range); self[range.end_open] - self[range.begin]; end
end

module Enumerable
  def sorted_uniq; x = nil; filter { |y| c = x === y; x = y; !c } end
  def cumsum; ys = [0]; each { |x| ys << x + ys[-1] }; ys end
end

main

def solve
  n, u, r, d, l = ints
  (1 << 4).times.any? do |bits|
    lu, ru, ld, rd = (0 ... 4).map { |i| bits[i] == 1 }
    possible = true
    possible &&= lu ? (l >= 1 and u >= 1) : (l <= n - 1 and u <= n - 1)
    possible &&= ru ? (r >= 1 and u >= 1) : (r <= n - 1 and u <= n - 1)
    possible &&= ld ? (l >= 1 and d >= 1) : (l <= n - 1 and d <= n - 1)
    possible &&= rd ? (r >= 1 and d >= 1) : (r <= n - 1 and d <= n - 1)
    possible &&= (lu and ru) ? (u >= 2) : true
    possible &&= (lu and ld) ? (l >= 2) : true
    possible &&= (ru and rd) ? (r >= 2) : true
    possible &&= (ld and rd) ? (d >= 2) : true
    possible
  end
end

def main
  t = int
  t.times do
    yesno solve
  end
end

DEBUG = true
MOD = 10**9+7
YESNO = %w(NO YES)
INF = 10**9

def int; gets.to_s.to_i end
def ints; gets.to_s.split.map { |s| s.to_i } end
def int1s; gets.to_s.split.map { |s| s.to_i - 1 } end
def float; gets.to_s.to_f end
def floats; gets.to_s.split.map { |s| s.to_f } end
def array_of(&convert); gets.to_s.split.map(&convert) end
def string; gets.to_s.chomp end
def rep(n, &b); Array.new(n, &b) end
def yes; puts YESNO[1] end
def no; puts YESNO[0] end
def yesno t; puts YESNO[t] end
def zip(xs, *yss); Enumerator.new { |y| xs.zip(*yss) { |a| y.yield(*a) } } end
def max(*xs, &block); block_given? ? xs.max_by(&block) : xs.max end
def min(*xs, &block); block_given? ? xs.min_by(&block) : xs.min end
def minmax(*xs, &block); block_given? ? xs.minmax_by(&block) : xs.minmax end
def gcd(*xs); xs.inject(0, :gcd) end
def matrix(h, w, fill=nil, &block); return Array.new(h) { Array.new(w, &block) } if block_given?; Array.new(h) { [fill] * w } end
def debug(x = nil); STDERR.puts (block_given? ? yield(x) : x).inspect if DEBUG; x end
def debug_grid(grid, width = 1); grid.each { |row| STDERR.puts row.map { |x| x.inspect.ljust(width) }.join("") } if DEBUG; grid end
def if_debug; yield if DEBUG end

module Boolean
  def coerce(other); [other, to_i] end
  def +@; to_i end
  def to_int; to_i end
  def *(other); to_i * other end
end

class TrueClass
  include Boolean
  def to_i; 1 end
end

class FalseClass
  include Boolean
  def to_i; 0 end
end

class Integer
  def div_ceil(y); (self + y - 1) / y end
  def mod_inv(mod = MOD); pow(mod-2, mod) end
  def mod_div(y, mod = MOD); self * mod_inv(y, mod) % mod end
  def factorial(mod = MOD); (2..self).inject(1) { |f, x| f * x % mod } end
  def popcount; x = self; c = 0; while x > 0; c += 1 if x & 1 == 1; x >>= 1 end; c end #TODO: faster
  def bitbrute(&block); (1<<self).times(&block) end
  def nCr(r); x = 1; (1..r).each { |i| x *= self + 1 - i; x /= i }; x; end
  def each_divisor; return Enumerator.new { |y| each_divisor { |k| y << k } } unless block_given?; k = 1; while k * k < self; if self % k == 0; yield k; yield self / k end; k += 1; end; yield k if k * k == self end
  def divisors; each_divisor.to_a end
end

class Range
  def end_open; exclude_end? ? self.end : self.end + 1 end
  def end_close; exclude_end? ? self.end - 1 : self.end end
  def upper_bound; ac, wa = self.begin, self.end_open; while wa - ac > 1; if yield((wj = (ac + wa) / 2)); ac = wj else wa = wj end; end; yield(ac) ? ac : nil end
  def lower_bound; ac, wa = self.end_open, self.begin; while ac - wa > 1; if yield((wj = (ac + wa) / 2)); ac = wj else wa = wj end; end; yield(ac) ? ac : nil end
  def shakutori(r2, &pred); Enumerator.new { |y| j, r = r2.begin, r2.end_open; each { |i| j += 1 while j + 1 < r and pred[i, j+1]; y.yield(i, j) } }; end
  def widest(&block); Enumerator.new { |y| j, n = self.begin, self.end_open; each { |i| j += 1 while j < n and block[i, j]; y.yield(i, j) if block[i, j] } } end
end

class Array
  def power(&block); (0 ... 1 << size).each(&block) end
  def sorted_merge(other); a = []; i = j = 0; n, m = size, other.size; if j < m and other[j] < self[i]; a << other[j]; j += 1 else; a << self[i]; i += 1 end while i < n; a.push(*other[j..-1]) if j < m; a end
  def upper_bound; ac, wa = 0, size; while wa - ac > 1; if yield(self[(wj = (ac + wa) / 2)]); ac = wj else; wa = wj end; end; ac end
  def lower_bound; ac, wa = size, 0; while wa - ac > 1; if yield(self[(wj = (ac + wa) / 2)]); ac = wj else; wa = wj end; end; ac end
  def cum(*xs, &op); a = []; a << xs[0] if xs.size > 0; a << x = self[0]; (1...size).each { |i| a << x = op[x, self[i]] }; a end
  def cumdiff(range); self[range.end_open] - self[range.begin]; end
end

module Enumerable
  def sorted_uniq; x = nil; filter { |y| c = x === y; x = y; !c } end
  def cumsum; ys = [0]; each { |x| ys << x + ys[-1] }; ys end
end

main

def solve
  n, u, r, d, l = ints
  (1 << 4).times.any? do |bits|
    lu, ru, ld, rd = (0 ... 4).map { |i| bits[i] == 1 }
    possible = true
    possible &&= lu ? (l >= 1 and u >= 1) : (l <= n - 1 and u <= n - 1)
    possible &&= ru ? (r >= 1 and u >= 1) : (r <= n - 1 and u <= n - 1)
    possible &&= ld ? (l >= 1 and d >= 1) : (l <= n - 1 and d <= n - 1)
    possible &&= rd ? (r >= 1 and d >= 1) : (r <= n - 1 and d <= n - 1)
    possible
  end
end

def main
  t = int
  t.times do
    yesno solve
  end
end

DEBUG = true
MOD = 10**9+7
YESNO = %w(NO YES)
INF = 10**9

def int; gets.to_s.to_i end
def ints; gets.to_s.split.map { |s| s.to_i } end
def int1s; gets.to_s.split.map { |s| s.to_i - 1 } end
def float; gets.to_s.to_f end
def floats; gets.to_s.split.map { |s| s.to_f } end
def array_of(&convert); gets.to_s.split.map(&convert) end
def string; gets.to_s.chomp end
def rep(n, &b); Array.new(n, &b) end
def yes; puts YESNO[1] end
def no; puts YESNO[0] end
def yesno t; puts YESNO[t] end
def zip(xs, *yss); Enumerator.new { |y| xs.zip(*yss) { |a| y.yield(*a) } } end
def max(*xs, &block); block_given? ? xs.max_by(&block) : xs.max end
def min(*xs, &block); block_given? ? xs.min_by(&block) : xs.min end
def minmax(*xs, &block); block_given? ? xs.minmax_by(&block) : xs.minmax end
def gcd(*xs); xs.inject(0, :gcd) end
def matrix(h, w, fill=nil, &block); return Array.new(h) { Array.new(w, &block) } if block_given?; Array.new(h) { [fill] * w } end
def debug(x = nil); STDERR.puts (block_given? ? yield(x) : x).inspect if DEBUG; x end
def debug_grid(grid, width = 1); grid.each { |row| STDERR.puts row.map { |x| x.inspect.ljust(width) }.join("") } if DEBUG; grid end
def if_debug; yield if DEBUG end

module Boolean
  def coerce(other); [other, to_i] end
  def +@; to_i end
  def to_int; to_i end
  def *(other); to_i * other end
end

class TrueClass
  include Boolean
  def to_i; 1 end
end

class FalseClass
  include Boolean
  def to_i; 0 end
end

class Integer
  def div_ceil(y); (self + y - 1) / y end
  def mod_inv(mod = MOD); pow(mod-2, mod) end
  def mod_div(y, mod = MOD); self * mod_inv(y, mod) % mod end
  def factorial(mod = MOD); (2..self).inject(1) { |f, x| f * x % mod } end
  def popcount; x = self; c = 0; while x > 0; c += 1 if x & 1 == 1; x >>= 1 end; c end #TODO: faster
  def bitbrute(&block); (1<<self).times(&block) end
  def nCr(r); x = 1; (1..r).each { |i| x *= self + 1 - i; x /= i }; x; end
  def each_divisor; return Enumerator.new { |y| each_divisor { |k| y << k } } unless block_given?; k = 1; while k * k < self; if self % k == 0; yield k; yield self / k end; k += 1; end; yield k if k * k == self end
  def divisors; each_divisor.to_a end
end

class Range
  def end_open; exclude_end? ? self.end : self.end + 1 end
  def end_close; exclude_end? ? self.end - 1 : self.end end
  def upper_bound; ac, wa = self.begin, self.end_open; while wa - ac > 1; if yield((wj = (ac + wa) / 2)); ac = wj else wa = wj end; end; yield(ac) ? ac : nil end
  def lower_bound; ac, wa = self.end_open, self.begin; while ac - wa > 1; if yield((wj = (ac + wa) / 2)); ac = wj else wa = wj end; end; yield(ac) ? ac : nil end
  def shakutori(r2, &pred); Enumerator.new { |y| j, r = r2.begin, r2.end_open; each { |i| j += 1 while j + 1 < r and pred[i, j+1]; y.yield(i, j) } }; end
  def widest(&block); Enumerator.new { |y| j, n = self.begin, self.end_open; each { |i| j += 1 while j < n and block[i, j]; y.yield(i, j) if block[i, j] } } end
end

class Array
  def power(&block); (0 ... 1 << size).each(&block) end
  def sorted_merge(other); a = []; i = j = 0; n, m = size, other.size; if j < m and other[j] < self[i]; a << other[j]; j += 1 else; a << self[i]; i += 1 end while i < n; a.push(*other[j..-1]) if j < m; a end
  def upper_bound; ac, wa = 0, size; while wa - ac > 1; if yield(self[(wj = (ac + wa) / 2)]); ac = wj else; wa = wj end; end; ac end
  def lower_bound; ac, wa = size, 0; while wa - ac > 1; if yield(self[(wj = (ac + wa) / 2)]); ac = wj else; wa = wj end; end; ac end
  def cum(*xs, &op); a = []; a << xs[0] if xs.size > 0; a << x = self[0]; (1...size).each { |i| a << x = op[x, self[i]] }; a end
  def cumdiff(range); self[range.end_open] - self[range.begin]; end
end

module Enumerable
  def sorted_uniq; x = nil; filter { |y| c = x === y; x = y; !c } end
  def cumsum; ys = [0]; each { |x| ys << x + ys[-1] }; ys end
end

main

def solve
  n, u, r, d, l = ints
  [[u, d, l, r], [u, d, r, l], [l, r, u, d], [l, r, d, u]].all? { |(x, y, z, w)|
    if x == n
      if y == n
        z >= 2 and w >= 2
      elsif y == n - 1
        z >= 2 and w >= 1
      else
        z >= 1 and w >= 1
      end
    elsif x == n - 1
      if y == n
        z >= 2 and w >= 1
      elsif y == n - 1
        z >= 2 or z >= 1 and w >= 1
      else
        z >= 1 or w >= 1
      end
    else
      if y == n
        z >= 1 and w <= n - 1
      elsif y == n - 1
        z >= 1 and w <= n - 2
      else
        z == n and w <= n - 2 or z == n - 1 and w <= n - 1 or z <= n - 2
      end
    end
  }
end

def main
  t = int
  t.times do
    yesno solve
  end
end

DEBUG = true
MOD = 10**9+7
YESNO = %w(NO YES)
INF = 10**9

def int; gets.to_s.to_i end
def ints; gets.to_s.split.map { |s| s.to_i } end
def int1s; gets.to_s.split.map { |s| s.to_i - 1 } end
def float; gets.to_s.to_f end
def floats; gets.to_s.split.map { |s| s.to_f } end
def array_of(&convert); gets.to_s.split.map(&convert) end
def string; gets.to_s.chomp end
def rep(n, &b); Array.new(n, &b) end
def yes; puts YESNO[1] end
def no; puts YESNO[0] end
def yesno t; puts YESNO[t] end
def zip(xs, *yss); Enumerator.new { |y| xs.zip(*yss) { |a| y.yield(*a) } } end
def max(*xs, &block); block_given? ? xs.max_by(&block) : xs.max end
def min(*xs, &block); block_given? ? xs.min_by(&block) : xs.min end
def minmax(*xs, &block); block_given? ? xs.minmax_by(&block) : xs.minmax end
def gcd(*xs); xs.inject(0, :gcd) end
def matrix(h, w, fill=nil, &block); return Array.new(h) { Array.new(w, &block) } if block_given?; Array.new(h) { [fill] * w } end
def debug(x = nil); STDERR.puts (block_given? ? yield(x) : x).inspect if DEBUG; x end
def debug_grid(grid, width = 1); grid.each { |row| STDERR.puts row.map { |x| x.inspect.ljust(width) }.join("") } if DEBUG; grid end
def if_debug; yield if DEBUG end

module Boolean
  def coerce(other); [other, to_i] end
  def +@; to_i end
  def to_int; to_i end
  def *(other); to_i * other end
end

class TrueClass
  include Boolean
  def to_i; 1 end
end

class FalseClass
  include Boolean
  def to_i; 0 end
end

class Integer
  def div_ceil(y); (self + y - 1) / y end
  def mod_inv(mod = MOD); pow(mod-2, mod) end
  def mod_div(y, mod = MOD); self * mod_inv(y, mod) % mod end
  def factorial(mod = MOD); (2..self).inject(1) { |f, x| f * x % mod } end
  def popcount; x = self; c = 0; while x > 0; c += 1 if x & 1 == 1; x >>= 1 end; c end #TODO: faster
  def bitbrute(&block); (1<<self).times(&block) end
  def nCr(r); x = 1; (1..r).each { |i| x *= self + 1 - i; x /= i }; x; end
  def each_divisor; return Enumerator.new { |y| each_divisor { |k| y << k } } unless block_given?; k = 1; while k * k < self; if self % k == 0; yield k; yield self / k end; k += 1; end; yield k if k * k == self end
  def divisors; each_divisor.to_a end
end

class Range
  def end_open; exclude_end? ? self.end : self.end + 1 end
  def end_close; exclude_end? ? self.end - 1 : self.end end
  def upper_bound; ac, wa = self.begin, self.end_open; while wa - ac > 1; if yield((wj = (ac + wa) / 2)); ac = wj else wa = wj end; end; yield(ac) ? ac : nil end
  def lower_bound; ac, wa = self.end_open, self.begin; while ac - wa > 1; if yield((wj = (ac + wa) / 2)); ac = wj else wa = wj end; end; yield(ac) ? ac : nil end
  def shakutori(r2, &pred); Enumerator.new { |y| j, r = r2.begin, r2.end_open; each { |i| j += 1 while j + 1 < r and pred[i, j+1]; y.yield(i, j) } }; end
  def widest(&block); Enumerator.new { |y| j, n = self.begin, self.end_open; each { |i| j += 1 while j < n and block[i, j]; y.yield(i, j) if block[i, j] } } end
end

class Array
  def power(&block); (0 ... 1 << size).each(&block) end
  def sorted_merge(other); a = []; i = j = 0; n, m = size, other.size; if j < m and other[j] < self[i]; a << other[j]; j += 1 else; a << self[i]; i += 1 end while i < n; a.push(*other[j..-1]) if j < m; a end
  def upper_bound; ac, wa = 0, size; while wa - ac > 1; if yield(self[(wj = (ac + wa) / 2)]); ac = wj else; wa = wj end; end; ac end
  def lower_bound; ac, wa = size, 0; while wa - ac > 1; if yield(self[(wj = (ac + wa) / 2)]); ac = wj else; wa = wj end; end; ac end
  def cum(*xs, &op); a = []; a << xs[0] if xs.size > 0; a << x = self[0]; (1...size).each { |i| a << x = op[x, self[i]] }; a end
  def cumdiff(range); self[range.end_open] - self[range.begin]; end
end

module Enumerable
  def sorted_uniq; x = nil; filter { |y| c = x === y; x = y; !c } end
  def cumsum; ys = [0]; each { |x| ys << x + ys[-1] }; ys end
end

main

def solve
  n, u, r, d, l = ints
  [[u, d, l, r], [u, d, r, l], [l, r, u, d], [l, r, d, u]].all? { |(x, y, z, w)|
    if x == n
      if y == n
        z >= 2 and w >= 2
      elsif y == n - 1
        z >= 2 and w >= 1
      else
        z >= 1 and w >= 1
      end
    elsif x == n - 1
      if y == n
        z >= 2 and w >= 1
      elsif y == n - 1
        z >= 2 or z >= 1 and w >= 1
      else
        z >= 1 or w >= 1
      end
    else
      true
    end
  }
end

def main
  t = int
  t.times do
    yesno solve
  end
end

DEBUG = true
MOD = 10**9+7
YESNO = %w(NO YES)
INF = 10**9

def int; gets.to_s.to_i end
def ints; gets.to_s.split.map { |s| s.to_i } end
def int1s; gets.to_s.split.map { |s| s.to_i - 1 } end
def float; gets.to_s.to_f end
def floats; gets.to_s.split.map { |s| s.to_f } end
def array_of(&convert); gets.to_s.split.map(&convert) end
def string; gets.to_s.chomp end
def rep(n, &b); Array.new(n, &b) end
def yes; puts YESNO[1] end
def no; puts YESNO[0] end
def yesno t; puts YESNO[t] end
def zip(xs, *yss); Enumerator.new { |y| xs.zip(*yss) { |a| y.yield(*a) } } end
def max(*xs, &block); block_given? ? xs.max_by(&block) : xs.max end
def min(*xs, &block); block_given? ? xs.min_by(&block) : xs.min end
def minmax(*xs, &block); block_given? ? xs.minmax_by(&block) : xs.minmax end
def gcd(*xs); xs.inject(0, :gcd) end
def matrix(h, w, fill=nil, &block); return Array.new(h) { Array.new(w, &block) } if block_given?; Array.new(h) { [fill] * w } end
def debug(x = nil); STDERR.puts (block_given? ? yield(x) : x).inspect if DEBUG; x end
def debug_grid(grid, width = 1); grid.each { |row| STDERR.puts row.map { |x| x.inspect.ljust(width) }.join("") } if DEBUG; grid end
def if_debug; yield if DEBUG end

module Boolean
  def coerce(other); [other, to_i] end
  def +@; to_i end
  def to_int; to_i end
  def *(other); to_i * other end
end

class TrueClass
  include Boolean
  def to_i; 1 end
end

class FalseClass
  include Boolean
  def to_i; 0 end
end

class Integer
  def div_ceil(y); (self + y - 1) / y end
  def mod_inv(mod = MOD); pow(mod-2, mod) end
  def mod_div(y, mod = MOD); self * mod_inv(y, mod) % mod end
  def factorial(mod = MOD); (2..self).inject(1) { |f, x| f * x % mod } end
  def popcount; x = self; c = 0; while x > 0; c += 1 if x & 1 == 1; x >>= 1 end; c end #TODO: faster
  def bitbrute(&block); (1<<self).times(&block) end
  def nCr(r); x = 1; (1..r).each { |i| x *= self + 1 - i; x /= i }; x; end
  def each_divisor; return Enumerator.new { |y| each_divisor { |k| y << k } } unless block_given?; k = 1; while k * k < self; if self % k == 0; yield k; yield self / k end; k += 1; end; yield k if k * k == self end
  def divisors; each_divisor.to_a end
end

class Range
  def end_open; exclude_end? ? self.end : self.end + 1 end
  def end_close; exclude_end? ? self.end - 1 : self.end end
  def upper_bound; ac, wa = self.begin, self.end_open; while wa - ac > 1; if yield((wj = (ac + wa) / 2)); ac = wj else wa = wj end; end; yield(ac) ? ac : nil end
  def lower_bound; ac, wa = self.end_open, self.begin; while ac - wa > 1; if yield((wj = (ac + wa) / 2)); ac = wj else wa = wj end; end; yield(ac) ? ac : nil end
  def shakutori(r2, &pred); Enumerator.new { |y| j, r = r2.begin, r2.end_open; each { |i| j += 1 while j + 1 < r and pred[i, j+1]; y.yield(i, j) } }; end
  def widest(&block); Enumerator.new { |y| j, n = self.begin, self.end_open; each { |i| j += 1 while j < n and block[i, j]; y.yield(i, j) if block[i, j] } } end
end

class Array
  def power(&block); (0 ... 1 << size).each(&block) end
  def sorted_merge(other); a = []; i = j = 0; n, m = size, other.size; if j < m and other[j] < self[i]; a << other[j]; j += 1 else; a << self[i]; i += 1 end while i < n; a.push(*other[j..-1]) if j < m; a end
  def upper_bound; ac, wa = 0, size; while wa - ac > 1; if yield(self[(wj = (ac + wa) / 2)]); ac = wj else; wa = wj end; end; ac end
  def lower_bound; ac, wa = size, 0; while wa - ac > 1; if yield(self[(wj = (ac + wa) / 2)]); ac = wj else; wa = wj end; end; ac end
  def cum(*xs, &op); a = []; a << xs[0] if xs.size > 0; a << x = self[0]; (1...size).each { |i| a << x = op[x, self[i]] }; a end
  def cumdiff(range); self[range.end_open] - self[range.begin]; end
end

module Enumerable
  def sorted_uniq; x = nil; filter { |y| c = x === y; x = y; !c } end
  def cumsum; ys = [0]; each { |x| ys << x + ys[-1] }; ys end
end

main

gets.to_i.times do
    n, u, r, d, l = gets.split.map &:to_i
    ok = false
    16.times do |msk|
        cu, cr, cd, cl = u, r, d, l
        if msk & 1 > 0
            cu -= 1
            cl -= 1
        elsif msk & 2 > 0
            cl -= 1
            cd -= 1
        elsif msk & 4 > 0
            cd -= 1
            cr -= 1
        elsif msk & 8 > 0
            cr -= 1
            cu -= 1
        end
        if [cu, cr, cd, cl].min >= 0 && [cu, cr, cd, cl].max <= n - 2
            puts "YES"
            ok = true
            break
        end
    end
    puts "NO" if !ok
end


#!/usr/bin/env ruby

n = gets.to_i
roads = Array.new(n) { [] }
n.times do
    r = gets.split.map(&:to_i)
    r[0] -= 1
    r[1] -= 1
    roads[r[0]] << r[1]
    roads[r[1]] << r[0]
end

eliminated = [false]*n
loop {
    flag = false
    roads.each_with_index do |r, idx|
        next if eliminated[idx]
        cnt = 0
        r.each do |i|
            cnt += 1 if !eliminated[i]
        end
        if cnt == 1
            eliminated[idx] = true
            flag = true
        end
    end
    break if !flag
}
lp = []
eliminated.each_with_index do |e, i|
    lp << i if !e
end

res = [nil]*n
q = []
lp.each do |i|
    q << [i, 0]
end
while q.size > 0
    cur = q.shift
    next if res[cur[0]]

    res[cur[0]] = cur[1]
    roads[cur[0]].each do |nx|
        q << [nx, cur[1]+1] unless res[nx]
    end
end

puts res.join(' ')

#!/usr/bin/env ruby

def find_loop(roads, stack, pos, visited)
    stack = [0]
    visited = [false]*roads.size

    roads[pos].each do |nx|
        if visited[nx]
            if stack.size >= 2 && stack[-2] != nx && stack.index(nx)
                res = []
                while stack[-1] != nx
                    res << stack.pop
                end
                res << stack.pop
                return res
            end
        else
            res = find_loop(roads, stack, nx, visited)
            return res if res
        end
    end
    visited[pos] = false
    stack.pop
    nil
end

def dfs(roads, pos, cost, res)
    res[pos] = cost
    roads[pos].each do |nx|
        next if res[nx]
        dfs(roads, nx, cost+1, res)
    end
end

n = gets.to_i
roads = Array.new(n) { [] }
n.times do
    r = gets.split.map(&:to_i)
    r[0] -= 1
    r[1] -= 1
    roads[r[0]] << r[1]
    roads[r[1]] << r[0]
end

eliminated = [false]*n
loop {
    flag = false
    roads.each_with_index do |r, idx|
        next if eliminated[idx]
        cnt = 0
        r.each do |i|
            cnt += 1 if !eliminated[i]
        end
        if cnt == 1
            eliminated[idx] = true
            flag = true
        end
    end
    break if !flag
}
lp = []
eliminated.each_with_index do |e, i|
    lp << i if !e
end

res = [nil]*n
q = []
lp.each do |i|
    q << [i, 0]
end
while q.size > 0
    cur = q.shift
    next if res[cur[0]]

    res[cur[0]] = cur[1]
    roads[cur[0]].each do |nx|
        q << [nx, cur[1]+1] unless res[nx]
    end
end

puts res.join(' ')

def cycle(node, e, r)
  que = [[node, r]]

  until que.empty?
    node, r = que.pop

    if r.include?(node)
      i = r.index(node)
      return r[i..-1]
    end

    e[node].each do |m|
      next if m == r.last

      que << [m, r+[node]]
    end
  end
  nil
end

n = gets.to_i
e = {}
while l = gets
  x, y = l.split.map(&:to_i)
  (e[x] ||= []) << y
  (e[y] ||= []) << x
end

c = cycle(1, e, [])
depth = {}
c.each{|x| depth[x] = 0 }
g = c
while depth.size < n
  g2 = []
  g.each do |x|
    e[x].each do |y|
      if !depth[y]
        depth[y] = depth[x]+1
        g2 << y
      end
    end
  end
  g = g2
end

puts (1..n).map{|x|depth[x]}*" "


#少计算就是打折！
#实在不成，我自己把c里面的merge sort搬过来！
number=gets.chomp.split
n=number[0].to_i
k=number[1].to_i
a=gets.chomp.split
b=gets.chomp.split
Pair=Struct.new(:index,:value)
indexed_ab=[]
for i in 0...n
	some=Pair.new(i,a[i].to_i-b[i].to_i)
	indexed_ab<<some
end
#看起来需要降价幅度最大的！优先更换！
#从大到小排序
indexed_ab.sort!{|a,b| b.value <=> a.value }
#新思路是做出一个替换!
#use[i]=0表示使用打折前的价格
#use[i]=1表示使用打折后的价格
#for i in 0...n
#	print "  #{indexed_ab[i].index} #{indexed_ab[i].value}"
#end
#puts
cost=0
item=n-k
for i in 0...n
	if indexed_ab[i].value>0 && item > 0
		cost+=b[indexed_ab[i].index].to_i
		#print " #{b[indexed_ab[i].index]}"
		item-=1
	else
		cost+=a[indexed_ab[i].index].to_i
		#print " #{a[indexed_ab[i].index]}"
	end
end
#puts
puts cost

n, k = gets.split.map(&:to_i)
aa = gets.split.map(&:to_i)
t = aa.inject(0, :+)
aa = aa.zip(gets.split.map(&:to_i)).map { |a, b| a - b }.sort
aa.push 0
while aa[k] < 0 do
  k += 1
end
p aa[k, n - k].inject(t, :-)

n, k = gets.split.map(&:to_i)
k = k.to_i
aa = gets.split.map(&:to_i)
bb = aa.zip(gets.split.map(&:to_i)).map { |a, b| a - b }.sort
bb.push 0
while bb[k] < 0 do
  k += 1
end
p aa.inject(bb[k, n - k].inject(0, :-), :+)

ii = lambda { gets.split.map(&:to_i) }
n, k = ii.call
t = (aa = ii.call).inject(0, :+)
(aa = aa.zip(ii.call).map { |a, b| a - b }.sort).push 0
while aa[k] < 0 do k += 1 end
p aa[k, n - k].inject(t, :-)

n, k = gets.chomp.split.map(&:to_i)
a_week = gets.chomp.split.map(&:to_i)
b_week = gets.chomp.split.map(&:to_i)
diff = []
Diff = Struct.new(:index, :diff,:purchased)
n.times do |i|
  diff << Diff.new(i,(a_week[i] - b_week[i]), false)
end
diff.sort! { |num1, num2| num1.diff <=> num2.diff}

negatives = diff.count{ |num| num.diff < 0}
minimum_money_spent = 0
[k,negatives].max.times do |i|
  curr_item = diff[i]
  minimum_money_spent += a_week[curr_item.index]
  curr_item.purchased = true
end
diff.each do |item|
  minimum_money_spent+= b_week[item.index] if item.purchased == false
end
puts minimum_money_spent

#少计算就是打折！
#实在不成，我自己把c里面的merge sort搬过来！
number=gets.chomp.split
n=number[0].to_i
k=number[1].to_i
a=gets.chomp.split
b=gets.chomp.split
Pair=Struct.new(:index,:value)
indexed_ab=[]
for i in 0...n
	some=Pair.new(i,a[i].to_i-b[i].to_i)
	indexed_ab<<some
end
#看起来需要降价幅度最大的！优先更换！
#从大到小排序
indexed_ab.sort!{|a,b| b.value <=> a.value }
#新思路是做出一个替换!
use=Array.new(n,0)
#use[i]=0表示使用打折前的价格
#use[i]=1表示使用打折后的价格
#for i in 0...n
#	print "  #{indexed_ab[i].index} #{indexed_ab[i].value}"
#end
#puts
for i in 0...(n-k)
	if indexed_ab[i].value>0
		use[indexed_ab[i].index]=1
	end
end
cost=0
for i in 0...n
	if use[i]==0
		cost+=a[i].to_i
		#print " #{a[i]}"
	else
		cost+=b[i].to_i
		#print " #{b[i]}"
	end
end
#puts
puts cost

#少计算就是打折！
number=gets.chomp.split
n=number[0].to_i
k=number[1].to_i
a=gets.chomp.split
b=gets.chomp.split
c=[]
Pair=Struct.new(:before,:after)
for i in 0...n
	some=Pair.new(a[i].to_i,b[i].to_i)
	c<<some
end
#for i in 0...n
	#puts "#{c[i].before} #{c[i].after}"
#end
#这里只需要判断最小值来自哪里！
c.sort_by!{|e|
	if e.after < e.before
		e.after
	elsif e.after == e.before
		e.before
	else
		e.before
	end

}
#for i in 0...n
#	puts "#{c[i].before} #{c[i].after}"
#end
buy_before=0
buy_after=0
j=0
for i in 0...n
	if c[i].before > c[i].after && j< n-k
		buy_after+= c[i].after
		j+=1
	else
		buy_before+= c[i].before
	end
end
puts buy_before+buy_after

#一个思路是：sort一下，就是把a,b作为整体来sort！
#取前k个a<b的，取前n-k个b>a的
#第二次购买，应该买那些年价格降低的！
#或者同时处理，遇到价格降低的当作第二次购买，
#遇到价格不变的，甚至升高的，放在第一次购买！

#少计算就是打折！
#实在不成，我自己把c里面的merge sort搬过来！
number=gets.chomp.split
n=number[0].to_i
k=number[1].to_i
a=gets.chomp.split
b=gets.chomp.split
Pair=Struct.new(:index,:value)
indexed_ab=[]
for i in 0...n
	some=Pair.new(i,a[i].to_i-b[i].to_i)
	indexed_ab<<some
end
#看起来需要降价幅度最大的！优先更换！
#从大到小排序
indexed_ab.sort!{|a,b| b.value <=> a.value }
#新思路是做出一个替换!
use=Array.new(n,0)
#use[i]=0表示使用打折前的价格
#use[i]=1表示使用打折后的价格
#for i in 0...n
	#print "  #{indexed_ab[i].index} #{indexed_ab[i].value}"
#end
#puts
for i in 0...(n-k)
	if indexed_ab[i].value==0
		break
	else
		use[indexed_ab[i].index]=1
	end
end
cost=0
for i in 0...n
	if use[i]==0
		cost+=a[i].to_i
		#print " #{a[i]}"
	else
		cost+=b[i].to_i
		#print " #{b[i]}"
	end
end
#puts
puts cost

#少计算就是打折！
#实在不成，我自己把c里面的merge sort搬过来！
number=gets.chomp.split
n=number[0].to_i
k=number[1].to_i
a=gets.chomp.split
b=gets.chomp.split
Pair=Struct.new(:index,:value)
indexed_a=[]
for i in 0...n
	some=Pair.new(i,a[i].to_i)
	indexed_a<<some
end
indexed_b=[]
for i in 0...n
	some=Pair.new(i,b[i].to_i)
	indexed_b<<some
end

indexed_a.sort!{|a,b| a.value <=> b.value }
indexed_b.sort!{|a,b| a.value <=> b.value }
#for i in 0...n
#	puts "#{indexed_a[i].index} #{indexed_a[i].value}"
#end
#for i in 0...n
#	puts "#{indexed_b[i].index} #{indexed_b[i].value}"
#end
#
see=Array.new(n,0)
i=0
j=0
cost=0
item=n-k
while true do
	while i<n && see[indexed_a[i].index]==1
	       i+=1
	end
	while j<n && see[indexed_b[j].index]==1
	       j+=1
	end
	if i==n && j==n
		break
	elsif i==n && j!=n
		#这里只能买打折后的了！
		cost+=indexed_b[j].value
		j+=1
	elsif i!=n && j==n
		#这里只能买打折前的了！
		cost+=indexed_a[i].value
		i+=1
	else
		#可以从打折前后选择最小的！
		if indexed_a[i].value > indexed_b[j].value
			#这里我们在还有可以买非必需现在买的商品的额度时，可以购买
			#如果没有额度了，就无法购买，只能现在就买！
			if item > 0
				cost+=indexed_b[j].value
				see[indexed_b[j].index]=1
				item-=1
				j+=1
			else
				j=n
			end

		else
			cost+=indexed_a[i].value
			see[indexed_a[i].index]=1
			i+=1
		end
	end
end
puts cost

#少计算就是打折！
#实在不成，我自己把c里面的merge sort搬过来！
number=gets.chomp.split
n=number[0].to_i
k=number[1].to_i
a=gets.chomp.split
b=gets.chomp.split
Pair=Struct.new(:index,:value)
indexed_ab=[]
for i in 0...n
	some=Pair.new(i,a[i].to_i-b[i].to_i)
	indexed_ab<<some
end
#看起来需要降价幅度最大的！优先更换！
#从大到小排序
indexed_ab.sort!{|a,b| b.value <=> a.value }
#新思路是做出一个替换!
#use[i]=0表示使用打折前的价格
#use[i]=1表示使用打折后的价格
#for i in 0...n
#	print "  #{indexed_ab[i].index} #{indexed_ab[i].value}"
#end
#puts
cost=0
for i in 0...n
	if indexed_ab[i].value>0
		cost+=b[indexed_ab[i].index].to_i
	else
		cost+=a[indexed_ab[i].index].to_i
	end
end
puts cost


#! ruby
# Try Codeforces
# author: Leonardone @ NEETSDKASU
############################################################
def gs() gets.chomp end
def gi() gets.to_i end
def gss() gs.split end
def gis() gss.map(&:to_i) end
def nmapf(n,f) n.times.map{ __send__ f } end
def ngs(n) nmapf n,:gs end
def ngi(n) nmapf n,:gi end
def ngss(n) nmapf n,:gss end
def ngis(n) nmapf n,:gis end
def arr2d(h,w,v=0) h.times.map{[v] * w} end
def for2p(hr,wr,&pr) hr.each{|i|wr.each{|j| yield(i,j)}} end
def nsum(n) n * (n + 1) / 2 end
def vcount(d,r=Hash.new(0)) d.inject(r){|r,e| r[e]+=1;r} end
############################################################

n, m = gis

b = [true] + [false] * m

n.times do
    x, *y = gis
    y.each do |j|
        b[j] = true
    end
end

puts b.all? ? :YES : :NO

nm = gets.chomp.split.map(&:to_i)
n = nm[0]
m = nm[1]
bulbs = []
for i in (0..n-1)
	bulbs[i] = gets.chomp.split.map(&:to_i)
end

turn_on = []
for i in (0..n-1)
	for x in (1..bulbs[i][0])
		if turn_on.include?(bulbs[i][x]) == false
			turn_on << bulbs[i][x]
		end
	end
end

if turn_on.size == m
	print "YES"
else
	print "NO"
end

class Solver
	def main
		n, m = gets.split.map { |x| x.to_i }
		f = Array.new(m + 1, false)
		n.times do
			a = gets.split.map { |x| x.to_i }
			a.shift
			a.each do |x|
				f[x] = true
			end
		end
		cnt = f.count(true)
		if cnt == m
			puts "YES"
		else
			puts "NO"
		end
	end
end
Solver.new.main

#!/usr/bin/ruby
n,m=gets.split.map(&:to_i)
a=[]
n.times{a|=gets.split.map(&:to_i)[1..-1]}
puts a.size==m ? :YES : :NO

n, m = gets.split.map(&:to_i)
bulbs = []
n.times{ bulbs |= gets.split[1..-1] }
puts bulbs.size == m ? 'YES' : 'NO'

n, m = gets.split.map(&:to_i)
bulbs = []
n.times{ bulbs |= gets.split.map(&:to_i)[1..-1] }
puts bulbs.size == m ? 'YES' : 'NO'

n, m = gets.split.map(&:to_i)
bulbs = Array.new(m, 0)
n.times do
  a = gets.split.map(&:to_i)[1..-1]
  a.each{|x| bulbs[x] = 1}
end
puts bulbs.inject(:+) == m ? 'YES' : 'NO'

n, m = gets.chomp.split(" ").map(&:to_i)
bulbs = []
n.times do
  y = gets.chomp.split(" ").map(&:to_i)
  x = y.shift
  bulbs += y
end
if bulbs.uniq.length == m then
  puts "YES"
else
  puts "NO"
end

_, nbulbs = ARGF.gets.chomp.split(" ").map { |s| s.to_i }

on = Array.new(nbulbs + 1) { |e| FALSE }
on[0] = TRUE

while line = ARGF.gets do
    conns = line.chomp.split(" ").map {|s| s.to_i}
    conns.shift
    for c in conns do
        on[c] = TRUE
    end
end

if on.all? then puts "YES" else puts "NO" end

a=gets.chomp.split(" ")
light=[]
1.upto(a[0].to_i) do
b=gets.chomp.split(" ")
b.shift
light += b
end
light.uniq!
if light.length<a[1].to_i
	puts "NO"
elsif a[1]=="0" || (a[1]=="0" && a[0]=="0")
 	puts "NO"
else
	puts "YES"
end

n, m = gets.split.map &:to_i
b = []
n.times do
  xs = gets.split.map &:to_i
  xs[1..-1].each {|x| b[x] = true}
end
puts b.count(true) == m ? 'YES' : 'NO'

require "set"

n, m = gets.split.map &:to_i
bulbs = Set.new
n.times do |_|
  bulbs.merge(gets.split[1..-1].map &:to_i)
end

if bulbs == (1..m).to_set
  puts "YES"
else
  puts "NO"
end

n,m= gets.strip.split.map(&:to_i)

blobs = Array.new(m, 1)
1.upto(n).each do
	ar = gets.strip.split.map(&:to_i)
	ar[1..-1].each do |e|
		blobs[e-1] = 0
	end
end

puts blobs.any?{|e| e ==1} ? 'NO' : 'YES'

n, m = gets.split.map(&:to_i)
btns = Array.new(m, false)
n.times do
  nums = gets.split.map(&:to_i)
  x = nums[0]
  next if x == 0
  nums[1..-1].each do |y|
    btns[y-1] = true
  end
end
puts btns.all?{|b| b} ? 'YES' : 'NO'

n,m=gets.split.map{|e| e.to_i}
arr=[]
n.times{
	x=gets.split.map{|e| e.to_i}
	x.shift
	arr<<x
}

puts (arr.flatten.uniq.size==m)?"YES":"NO"

n, m = gets.split.map(&:to_i)

a = Array.new(m, 0)

n.times do
  x = gets.split.map(&:to_i)
  x.shift
  x.each do |v|
    a[v - 1] = 1
  end
end

if a.include?(0)
  puts 'NO'
else
  puts 'YES'
end

# coding: utf-8

n, m = gets.split.map(&:to_i)
bulbs = Array.new(m) { false }
n.times {
    presses = gets.split.map(&:to_i)
    presses.shift # first item for how many commands are coming to next
    presses.each { |i|
        bulbs[i - 1] = true
    }
}

if bulbs.count(false) == 0
    puts "YES"
else
    puts "NO"
end

n, m = gets.chomp.split.map(&:to_i)
ys = []
n.times do
  xy = gets.chomp.split.map(&:to_i)
  ys += xy[1, xy[0]]
  ys.sort!.uniq!
end

puts ys.size == m ? 'YES' : 'NO'

n, m = gets.split.map(&:to_i)
btns = Array.new(m, false)
n.times do
  gets.split.map(&:to_i).each do |b|
    btns[b-1] = true
  end
end
puts btns.all?{|b| b} ? 'YES' : 'NO'

n, m = gets.split.map(&:to_i)
buttons = []
n.times do
  buttons << gets.split.map(&:to_i)
end
puts buttons.flatten.uniq.size == m ? 'YES' : 'NO'

n, m = gets.split.map(&:to_i)
btns = []
n.times do
  btn = gets.split.map(&:to_i)[0..m-1]
  next if btn.first == 0
  btns << btn
end
puts btns.flatten.uniq.size == m ? 'YES' : 'NO'

n, m = gets.split.map(&:to_i)
btns = Array.new(m, false)
n.times do
  gets.split.map(&:to_i)[0..m-1].each do |b|
    next if b == 0
    btns[b-1] = true
  end
end
puts btns.all?{|b| b} ? 'YES' : 'NO'

n,m=gets.split.map{|e| e.to_i}
puts (STDIN.read.split.uniq.count==m)?"YES":"NO"

n, m = gets.split.map(&:to_i)
bulbs = Array.new(m, 0)
n.times do
  a = gets.split.map(&:to_i)
  a.each{|x| bulbs[x] = 1}
end
puts bulbs.inject(:+) == m ? 'YES' : 'NO'

require "set"

n, m = gets.split.map &:to_i
bulbs = Set.new
n.times do |_|
  bulbs.merge(gets.split.map &:to_i)
end

if bulbs == (1..m).to_set
  puts "YES"
else
  puts "NO"
end

#Good luk for the Contest 615, Problem: a
n, m = gets.strip.split.map(&:to_i)
blubs = Array.new(m, 1)

1.upto(n).each do |i|
	b = gets.strip.split.map(&:to_i)

	b.each do |e|
		blubs[e-1] = 0 if blubs[e-1] == 1
	end
	if blubs.all?{|item| item == 0}
		break
	end
end

puts   blubs.all?{|e| e == 0} ? 'YES' : 'NO'

#Good luk for the Contest 615, Problem: a
n, m = gets.strip.split.map(&:to_i)
blubs = Array.new(m, 1)

1.upto(n).each do |i|
	b = gets.strip.split.map(&:to_i)

	b.each do |e|
		blubs[e-1] = 0 if blubs[e-1] == 1
	end
end

puts   blubs.all?{|e| e == 0} ? 'YES' : 'NO'

a=gets.chomp.split(" ")
light=[]
1.upto(a[0].to_i){light +=gets.chomp.split(" ")}
light.uniq!
if light.length<a[1].to_i
	puts "NO"
elsif a[1]=="0" || (a[1]=="0" && a[0]=="0")
 	puts "NO"
else
	puts "YES"
end

a=gets.chomp.split(" ")
light=[]
1.upto(a[0].to_i){light +=gets.chomp.split(" ")}
light.uniq!
if light.length<a[1].to_i
	puts "No"
else
	puts "YES"
end

a=gets.chomp.split(" ")
light=[]
1.upto(a[0].to_i){light +=gets.chomp.split(" ")}
light.uniq!
if light.length<a[1].to_i
	puts "No"
elsif a[1]=="0"
 	puts "NO"
else
	puts "Yes"
end

n, m = gets.split.map(&:to_i)
btns = []
n.times do
  btns << gets.split.map(&:to_i)[0..m-1]
end
puts btns.flatten.uniq.size == m ? 'YES' : 'NO'

n, m = gets.split.map(&:to_i)
btns = Array.new(m, false)
n.times do
  gets.split.map(&:to_i)[0..m-1].each do |b|
    btns[b-1] = true
  end
end
puts btns.all?{|b| b} ? 'YES' : 'NO'


gets.to_i.times do
  n = gets.to_i
  n /= 2 while n%2 == 0
  puts n == 1 ? 'NO' : 'YES'
end

gets.to_i.times do
	n = gets.to_i
	puts n.to_s(2).count(?1) == 1 ? "NO" : "YES"
end

gets.to_i.times do
  n = gets.to_i
  puts n & (n - 1) == 0 ? "NO": "YES"
end

gets.to_i.times do
  n = gets.to_i
  n /= 2 while n % 2 == 0
  puts n == 1 ? "NO" : "YES"
end

t = gets.chomp.to_i
t.times do
    n = gets.chomp.to_i
    ok = false
    if n == 1
        puts "NO"
    else
        while true
            amari = n % 2
            if amari == 0
                n = n / 2
            else
                break
            end
        end
        if n == 1
            puts "NO"
        else
            puts "YES"
        end
    end
end

gets.to_i.times do
  n=gets.to_i
  while n%2==0
    n/=2
  end
  if n.odd?&&n>1
    puts "YES"
  else
    puts "NO"
  end
end

def method(n)
  while n % 2 == 0
    n /= 2
  end
  n != 1
end

t = gets.to_i
t.times do
  n = gets.to_i
  puts method(n) ? "YES" : "NO"
end

n = gets.chomp.to_i;
while n != 0
    n = n-1;
    value = gets.chomp.to_i;
   # puts value.class
#=begin
    while value%2 == 0
        value = value/2;
    end
    if value > 1
     puts "YES"
    else
     puts "NO"
    end
#=end
end

def is_power_of_two(n)
  while n
    if n % 2 == 0
      n /= 2
    elsif (n % 2 == 1) && (n > 1)
      return false
    elsif n == 1
      return true
    end
  end
  return true
end

test_case = gets().to_i
test_case.times do
  n = gets().to_i
  if is_power_of_two(n)
    puts "NO"
  else
    puts "YES"
  end
end

def is_power_of_two(n)
  loG = Math.log(n)/Math.log(2.0)
  if loG-loG.to_i === 0
    return true
  end
  return false
end

test_case = gets().to_i
test_case.times do
  n = gets().to_f
  if is_power_of_two(n)
    puts "NO"
  else
    puts "YES"
  end
end

def is_power_of_two(n)
  loG = Math.log(n)/Math.log(2.0)
  if loG-loG.to_i === 0
    return true
  end
  return false
end

test_case = gets().to_i
test_case.times do
  n = gets().to_f
  if n % 2.0 == 0.0 && is_power_of_two(n)
    puts "NO"
  else
    puts "YES"
  end
end

def is_power_of_two(n)
  loG = Math.log(n)/Math.log(2)
  if loG-loG.to_i === 0
    return true
  end
  return false
end

test_case = gets().to_i
test_case.times do
  n = gets().to_i
  if n % 2 == 0 && is_power_of_two(n)
    puts "NO"
  else
    puts "YES"
  end
end

def is_power_of_two(n)
  if n === 2
    return true
  end
  while n
    n /= 2
    if n % 2 == 1
      return false
    end
  end
  return true
end

test_case = gets().to_i
test_case.times do
  n = gets().to_i
  if n % 2 == 0 && is_power_of_two(n)
    puts "NO"
  else
    puts "YES"
  end
end

gets.to_i.times do
  puts gets.to_i%2 == 0 ? 'NO' : 'YES'
end

gets.to_i.times do
  n=gets.to_i
  if n.odd?&&n>1
    puts "YES"
  else
    puts "NO"
  end
end


t = gets.chomp.to_i
t.times do
  n = gets.chomp.to_i
  arr = []
  n.times do
    arr << gets.chomp.split('').map(&:to_s)
  end
  i_f = n - 1
  inv = []
  case
    when arr[0][1] == arr[1][0]
      if arr[i_f][i_f - 1] == arr[0][1]
        inv << [i_f + 1, i_f]
      end
      if arr[i_f - 1][i_f] == arr[0][1]
        inv << [i_f, i_f + 1]
      end
    when arr[i_f][i_f - 1] == arr[i_f - 1][i_f]
      if arr[1][0] == arr[i_f][i_f - 1]
        inv << [2, 1]
      end
      if arr[0][1] == arr[i_f][i_f - 1]
        inv << [1, 2]
      end
    when arr[0][1] == arr[i_f - 1][i_f]
      inv << [1, 2]
      inv << [i_f + 1, i_f]
    when arr[0][1] == arr[i_f][i_f - 1]
      inv << [1, 2]
      inv << [i_f, i_f + 1]
  end
  puts inv.size
  inv.map{|x| puts x.join(' ')}
end


_N, _S = gets.split.map &:to_i
_A = gets.split.map &:to_i
lb, ub, cost = 0, _N + 1, 0
until lb + 1 == ub
  mb = lb + ub >> 1
  _C = (0..._N).collect { |i| _A[i] + (i + 1) * mb }.sort
  mc = _C[0, mb].reduce :+
  if mc <= _S
    lb, cost = mb, mc
  else
    ub = mb
  end
end
print [lb, cost].join " "; puts

N, S = gets.split.map &:to_i
A = gets.split.map &:to_i
l, u, c = 0, N + 1, 0
until l + 1 == u
  m = l + u >> 1
  f = (0...N).collect { |i| A[i] + (i + 1) * m }.sort[0, m].reduce :+
  f <= S ? (l, c = m, f) : u = m
end
p l, c


t = gets.to_i
t.times do
	s,a,b,c = gets.split.map(&:to_i)
	puts s/c + s/c/a*b
end

def max(s,a,b,c)
    r = (s/c)
    return r+(r/a)*b
end

t = gets.to_i
t.times{
    s,a,b,c = gets.split.map(&:to_i)
    puts max(s,a,b,c)
}

for i in 1..Integer(gets)
    s,a,b,c = gets.split.map{|x| Integer(x)}
    n = s/c;
    puts n + (n / a * b)
end

t = gets.to_i
t.times do
  s, a, b, c = gets.split.map(&:to_i)
  num = s / c
  num += (num/a) * b
  puts num
end

gets.to_i.times do
    s,a,b,c=gets.split.map &:to_i
    x=s/c
    puts x+x/a*b
end

t = gets.to_i
for i in 0...t
  s, a, b, c = gets.split.map(&:to_i)
  q = s / c
  puts b * (q / a) + q
end

t = gets.to_i
t.times do
    s, a, b, c = gets.split.map(&:to_i)
    x = s / c
    x = (x / a) * (a + b) + (x % a)
    puts x
end

t = gets.to_i
t.times do
    s,a,b,c = gets.chomp.split.map(&:to_i)
    p (s/(a*c))*(a+b)+(s-(s/(a*c))*a*c)/c
end

t = gets.to_i
t.times do
  s, a, b, c = gets.split.map &:to_i
  n = s/c
  puts n + n/a*b
end

for i in 1..Integer(gets)
    s,a,b,c = gets.split.map{|x| Integer(x)}
    n = s/c;
    puts n + (n * b / a)
end


n, a, b = gets.split.map{|x| x.to_i}
s = gets.strip.split('')
puts(s[a - 1] == s[b - 1] ? 0 : 1)

n, a, b = gets.split.map(&:to_i)

airports = gets.chomp

if (airports[a - 1] == '0' && airports[b - 1] == '0') || (airports[a - 1] == '1' && airports[b - 1] == '1')
	puts 0
else
	puts 1
end

n, a, b = gets.split.map(&:to_i)
str = gets.chomp
puts str[a - 1] != str[b - 1] ? 1 : 0

n,s,e = gets.split.map(&:to_i)
route = gets
if route[s-1] == route[e-1] then puts "0" else puts "1" end

n, a, b = gets.split(" ").map(&:to_i)
s = gets
a -= 1
b -= 1
puts s[a] == s[b] ? 0 : 1

n, a, b = gets.strip.split.map(&:to_i)
airports = gets.strip.split("").map(&:to_i)
a -= 1
b -= 1
puts airports[a] ^ airports[b]

n,a,b=gets.split.map{|e| e.to_i-1}
x=gets.chomp
puts (x[a]!=x[b])?1:0

n,a,b = gets.chomp.split(" ").map(&:to_i)
s = gets.split("")
puts s[a-1] == s[b-1] ? 0 : 1

n,a,b=gets.split.map &:to_i
s=" "<< gets
puts (s[a]==s[b] ? 0 : 1)

input = Array.new
while i = $stdin.gets
  input << i.strip
end

n_airports, start_id, target_id = input.shift.split.map(&:to_i)
airports_companies = input.shift

cost = airports_companies[start_id - 1].to_i - airports_companies[target_id - 1].to_i
puts cost.abs

n, a, b = gets.split.map( &:to_i )
s = gets
p ( s[ a - 1 ] != s[ b - 1 ] ? 1 : 0 )

n, a, b = gets.split.map(&:to_i)

airports = gets.chomp

if (airports[a - 1] == 0 && airports[b - 1] == 0) || (airports[a - 1] == 1 && airports[b - 1] == 1)
	puts 0
else
	puts 1
end

n, a, b = gets.strip.split.map(&:to_i)
airports = gets.strip.split("").map(&:to_i)
ans = 0
a -= 1
b -= 1
if a != b && airports[a] != airports[b]
    j = a
    if a < b
        while airports[j] != airports[b]
            j += 1
        end
    else
        while airports[j] != airports[b]
            j -= 1
        end
    end
    ans += (a - j).abs
end
puts ans

n, a, b = gets.strip.split.map(&:to_i)
airports = gets.strip.split("").map(&:to_i)
first = airports.each_index.select { |i| airports[i] == 0 }.sort
second = airports.each_index.select { |i| airports[i] == 1 }.sort
ans = 0
a -= 1
b -= 1
if a != b && airports[a] != airports[b]
    j = 0
    if a < b
        j = second.shift if airports[a] == 0
        j = first.shift if airports[a] == 1
    else
        j = second.pop if airports[a] == 0
        j = first.pop if airports[a] == 1
    end
    ans += (a - j).abs
end
puts ans

n, a, b = gets.strip.split.map(&:to_i)
airports = gets.strip.split("").map(&:to_i)
first = airports.each_index.select { |i| airports[i] == 0 }.sort
second = airports.each_index.select { |i| airports[i] == 1 }.sort
ans = 0
a -= 1
b -= 1
if airports[a] != airports[b]
    if airports[a] == 0
        ans += (a - second.shift).abs
    else
        ans += (a - first.shift).abs
    end
end
puts ans


o=gets.chomp
k=0
l=0
o.length.times do |i|
if o[i]=='x'
    k+=1
else
    l+=1
end
end
j=k-l
g=l-k
if k>l
    j.times do
    print "x"
    end
elsif l>k
    g.times do
    print "y"
    end
else
    print "\n"
end

input = gets.chomp

x = input.count 'x'
y = input.count 'y'

if x > y
  puts 'x'*(x-y)
else
  puts 'y'*(y-x)
end

s=gets.split(//)

a = 0
b = 0

s.each do |i|
	a += 1 if i == 'x'
	b += 1 if i == 'y'
end

puts 'x'*(a-b) if a > b
puts 'y'*(b-a) if b > a

e=gets
x=e.count("x")
y=e.count("y")
puts x>y ? 'x'*(x-y) : 'y'*(y-x)

s = gets.chomp
cntx = s.count("x")
cnty = s.count("y")
if cntx > cnty
    puts "x"*(cntx-cnty)
else
    puts "y"*(cnty-cntx)
end

a=gets.chomp

x=a.count('x')
y=a.count('y')

if x>y
  puts 'x'*(x-y)
else
  puts 'y'*(y-x)
end

a=gets.chomp.chars.to_a

x=a.count('x')
y=a.count('y')

if x>y
  puts 'x'*(x-y)
else
  puts 'y'*(y-x)
end

text = STDIN.gets
x_count, y_count = 0, 0
text.length.times{|i|
	case text[i,1]
	when "x"
		x_count += 1
	when "y"
		y_count += 1
	end
}
if x_count > y_count
	puts "x" * (x_count - y_count)
elsif y_count > x_count
	puts "y" * (y_count - x_count)
end

s = gets.strip.split //
y = 0
x = 0
0.upto(s.size-1) do |i|
  if s[i] == 'y'
    y += 1
  else
    x +=1
  end
end

y
if y>x
  puts "y"*(y-x)
else
  puts "x"*(x-y)
end

count = [0, 0]
gets.strip.each_char do |c|
    count[c == 'x' ? 0 : 1] += 1
end
if count[0] > count[1]
    puts "x" * (count[0] - count[1])
else
    puts "y" * (count[1] - count[0])
end

s=gets.to_s.chomp
s.count('x')>s.count('y')? (print 'x'*(s.count('x')-s.count('y'))) : (print 'y'*(s.count('y')-s.count('x')))

# -*- encoding: utf-8 -*-
# $stdin = File.open("input.txt")
# $stdout = File.open("output.txt", "w")

s = gets.chomp

x = s.count('x')
y = s.count('y')

if x > y
  puts "x" * (x - y)
else
  puts "y" * (y - x)
end

#!/usr/bin/ruby

s = STDIN.readline.strip

x, y = s.count('x'), s.count('y')

if x > y
	puts 'x'*(x-y)
else
	puts 'y'*(y-x)
end

s = gets.chomp
x = s.count("x")
y = s.count("y")

if x > y
  puts "x"*(x-y)
else
  puts "y"*(y-x)
end

def run
  line = ARGF.readline.chomp

  x = 0; y = 0
  line.split(//).each do |c|
    x += 1 if c == 'x'
    y += 1 if c == 'y'
  end

  if x > y
    puts "x" * (x - y)
  else
    puts "y" * (y - x)
  end
end

run if $0 == __FILE__

s = gets
puts s.count("x") > s.count("y") ? "x" * (s.count("x")-s.count("y")) : "y" * (s.count("y")-s.count("x"))

# -*- encoding: utf-8 -*-
# $stdin = File.open("input.txt")
# $stdout = File.open("output.txt", "w")

s = gets.chomp

s.gsub!(/yx/, "xy")
s.gsub!(/xy/, "")

puts s

# -*- encoding: utf-8 -*-
# $stdin = File.open("input.txt")
# $stdout = File.open("output.txt", "w")

def op1(s)
  s.sub(/yx/, "xy")
end

def op2(s)
  s.sub(/xy/, "")
end

s = gets.chomp

s.gsub!(/yx/, "")
s.gsub!(/xy/, "")

puts s

# -*- encoding: utf-8 -*-
# $stdin = File.open("input.txt")
# $stdout = File.open("output.txt", "w")

def op1(s)
  s.sub(/yx/, "xy")
end

def op2(s)
  s.sub(/xy/, "")
end

s = gets.chomp
loop do
  tmp = s
  s1 = op1(s)
  if s = s1
    s = s1
  else
    s = op2(s)
  end

  break if tmp == s
end

puts s

s = gets
s = s.gsub("xy", "")
s = s.gsub("yx", "xy")
s = s.gsub("xy", "")
puts s

o=gets.chomp
x=0
y=0
o.length.times do |i|
if o[i]=='x'
    x+=1
else
    y+=1
end
end
if x>y
    x-y.times do
    print x
    end
elsif y>x
    y-x.times do
    print y
    end
else
    print "\n"
end


gets.to_i.times do
  w,h,n=gets.split.map(&:to_i)
  c=1
  while w.even?
    w/=2
    c*=2
  end
  while h.even?
    h/=2
    c*=2
  end
  if c>=n
    puts "YES"
  else
    puts "NO"
  end
end

def zeros(n)
  n.even? ? zeros(n >> 1) * 2 : 1
end

gets.to_i.times {
  w, h, n = gets.split.map!(&:to_i)
  puts n <= zeros(w) * zeros(h) ? "YES" : "NO"
}

def solve
  w, h, n = gets.split.map(&:to_i)
  x = 1
  while w > 0 and w.even?
    x <<= 1
    w >>= 1
  end
  while h > 0 and h.even?
    x <<= 1
    h >>= 1
  end
  puts (x >= n) ? "YES" : "NO"
end

t = gets.to_i
t.times do
  solve
end

def method(v)
  res = 1
  res *= 2 while v % (2 * res) == 0
  res
end

t = gets.to_i
t.times do
  w, h, n = gets.split.map { |x| x.to_i }
  puts n <= method(w) * method(h) ? "YES" : "NO"
end

gets.to_i.times do
	a, b, n = gets.split.map(&:to_i)
	x, y = a, b
	x /= 2 while x.even?
	y /= 2 while y.even?

	puts (a / x) * (b / y) >= n ? 'YES' : 'NO'
end

require 'prime'
t = gets.chomp.to_i
t.times do
  w, h, n = gets.chomp.split(' ').map(&:to_i)
  res = 1
  while w % 2 == 0 || h % 2 == 0
    res *= 2
    if w % 2 == 0
      w /= 2
    else
      h /= 2
    end
  end
  puts n <= res ? "YES" : "NO"
end

n = $stdin.gets.to_i

n.times do
  w, h, x = $stdin.gets.split.map &:to_i
  wc = 1
  while w % 2 == 0
    wc *= 2
    w /= 2
  end

  hc = 1
  while h % 2 == 0
    hc *= 2
    h /= 2
  end

  if hc * wc >= x
    puts 'yes'
  else
    puts 'no'
  end
end

#!/usr/bin/env ruby

def count_num(len)
    res = 1
    while len.even? do
        res *= 2
        len /= 2
    end
    return res
end

tests_count = gets.to_i
tests_count.times {
    w, h, n = gets.split.map &:to_i
    res = count_num(w) * count_num(h)
    puts res >= n ? "YES" : "NO"
}

gets.to_i.times do
  w, h, n = gets.split.map &:to_i
  res = 1
  while w % 2 == 0
    w /= 2
    res *= 2
  end
  while h % 2 == 0
    h /= 2
    res *= 2
  end
  puts res >= n ? "YES" : "NO"
end

require "prime"
t = gets.chomp.to_i
t.times do
    w, h, n = gets.chomp.split(" ").map(&:to_i)
    cnt_w = w.prime_division
    cnt_h = h.prime_division
    cnt = 1
    cnt_w.each do |i,j|
        if i == 2
            cnt *= i ** j
        end
    end
    cnt_h.each do |i,j|
        if i == 2
            cnt *= i ** j
        end
    end
    if cnt >= n
        puts "YES"
    else
        puts "NO"
    end
end

a = gets.to_i
for i in 1..a do
    b = gets.chop
    c = b.split(/ /).map(&:to_i)
    w = c[0]
    h = c[1]
    n = c[2]
    i = 0
    j = 0
    while w % 2 == 0
        i += 1
        w = w / 2
    end
    while h % 2 == 0
        j += 1
        h = h / 2
    end
    if 2 ** (i+j) >= n
        print("YES", "\n")
    else
        print("NO", "\n")
    end
end

a = gets.to_i
for i in 1..a do
    b = gets.chop
    c = b.split(/ /).map(&:to_i)
    w = c[0]
    h = c[1]
    n = c[2]
    i = 0
    j = 0
    while w % 2 == 0
        i += 1
        w = w / 2
    end
    while h % 2 == 0
        j += 1
        h = h / 2
    end
    if ((i+1) * (j+1)) >= n
        print("YES", "\n")
    else
        print("NO", "\n")
    end
end

a = gets.to_i
for i in 1..a do
    b = gets.chop
    c = b.split(/ /).map(&:to_i)
    w = c[0]
    h = c[1]
    n = c[2]
    i = 0
    j = 0
    while w % 2 == 0
        i += 1
        w = w / 2
    end
    while h % 2 == 0
        j += 1
        h = h / 2
    end
    print(((i+1) * (j+1)) >= n, "\n")
end

a = gets.to_i
for i in 1..a do
    b = gets.chop
    c = b.split(/ /).map(&:to_i)
    w = c[0]
    h = c[1]
    n = c[2]
    i = 0
    j = 0
    while w % 2 == 0
        i += 1
        w = w / 2
    end
    while h % 2 == 0
        j += 1
        h = h / 2
    end
    print(((i+1) * (j+1)) >= n)
end

require 'prime'
t = gets.chomp.to_i
t.times do
  w, h, n = gets.chomp.split(' ').map(&:to_i)
  w1 = Prime.prime_division(w)[0]
  h1 = Prime.prime_division(h)[0]
  res = 0
  res += 2 ** w1[1] if w1 && w1[0] == 2
  res += 2 ** h1[1] if h1 && h1[0] == 2
  puts n <= [res, 1].max ? "YES" : "NO"
end

require 'prime'
t = gets.chomp.to_i
t.times do
  w, h, n = gets.chomp.split(' ').map(&:to_i)
  w1 = Prime.prime_division(w)[0]
  h1 = Prime.prime_division(h)[0]
  res = 1
  res += 2 ** w1[1] if w1 && w1[0] == 2
  res += 2 ** h1[1] if h1 && h1[0] == 2
  puts n <= res ? "YES" : "NO"
end


n, k = gets.split.map &:to_i
participation_count = gets.split.map &:to_i

participation_count.sort!

teams_count = 0
(2 ... n).step(3) do |i|
  teams_count += 1 if participation_count[i] + k <= 5
end

puts teams_count

n, k = gets.split(' ').map(&:to_i)
puts gets.split(' ',n).map(&:to_i).select{|x| x+k<=5}.count / 3

n, k = gets.split.map(&:to_i)
y = gets.split.map(&:to_i)
y.sort!
i = 0
while (i * 3 + 2 < n) && (y[i * 3 + 2] + k <= 5)
	i += 1
end
puts i

n,k=gets.split.map &:to_i
m=gets.split.map &:to_i
p=0
m.each { |x| p+=1 if x+k<=5 }
puts p/3

n,k=gets.split.map(&:to_i)
puts (gets.split.map(&:to_i).select{|i| i<=5-k}.size)/3

n,k = gets.split.map(&:to_i)
puts (gets.split.map(&:to_i).select{|i| i<=5-k}.size)/3

answer = 0
n, k = gets.split.map(&:to_i)
gets.split.map(&:to_i).each { |x| answer +=1 if k+x <= 5 }
puts (answer/3).floor

n, k = gets.split.map &:to_i
counter = 0
puts gets.split.map { |x| x.to_i }.count { |x| x + k <= 5 } / 3

(n , k) = gets.split.map(&:to_i)
arr = gets.split.map(&:to_i)
cnt = 0
arr.each do |num|
  if 5 - num >=k
    cnt+=1
  end
end
puts cnt / 3

n, k = gets.split(' ').map(&:to_i)
a = gets.split(' ').map(&:to_i)
count = [0, 0, 0, 0, 0, 0]
for x in a
  count[x] += 1
end
sum = 0
(6-k).times{|i|
  sum += count[i]
}
puts sum/3

n, k = gets.split.map(&:to_i)
ys = gets.split.map(&:to_i)

members = 0
ys.each do |y|
  if 5 - y >= k
    members += 1
  end
end
puts members / 3

n, k = gets.chomp.split(/ /).map(&:to_i)
students = gets.chomp.split(/ /).map(&:to_i)
if n < 3
    puts "0"
else
    teams = []
    students.reject! { |s| s == 5 }
    students.reject! { |s| s > 5 - k }
    while students.length >= 3
        teams << students[0..2]
        (0..2).each do |s|
            students.delete_at s
        end
    end
    puts teams.length
end

n,k=gets.split.map{|e| e.to_i}
x=gets.split.map{|e| 5-e.to_i}.count{|e| e>=k}
p x/3

n,k = gets.split.map(&:to_i)
puts gets.split.map(&:to_i).sort.count{|i| i + k <= 5} /3

s, n, k = [0] + gets.chomp.split.map{|e| e.to_i}

gets.chomp.split.map{|e| e.to_i}.sort.each_slice(3).to_a.each {|e| s += 1 if e.length == 3 and e.all? {|t| 5 - t >= k}}

puts s

#!/usr/bin/ruby

class Solver
    def solve()
        n, k = STDIN.gets.split(" ").map(&:to_i)
        times = STDIN.gets.split(" ").map(&:to_i)
        valid = 0
        times.each do |t|
            valid = valid + 1 if t + k <= 5
        end

        puts valid / 3
    end
end

Solver.new.solve()

n = gets.chomp
n = n.split
number_of_participants = n[0].to_i
times_needed = n[1].to_i
part = gets.chomp
participated = part.split

possible_teams = number_of_participants/3
count = 0
for i in (0..number_of_participants-1)
	if participated[i].to_i + times_needed <= 5
		count += 1
	end
end

if count >= 3
	puts count/3
else
	puts 0
end

first_line = gets.split(" ")
n = first_line[0].to_i
k = first_line[1].to_i
ys = gets.split(" ").collect {|x| x.to_i}
count = 0
for i in ys
  if k + i <= 5
    count += 1
  end
end
puts (count / 3)

line1=gets.chomp.split(" ").map!{|x| x.to_i}
n=line1[0];k=line1[1]
line2=gets.chomp.split(" ").map!{|x| x.to_i}
def Solve(list,k)
  list.select! {|x| 5-x>=k }
  puts list.size/3
end
Solve(line2,k)

n,k = gets.split(" ").map(&:to_i)
no_participations = gets.split(" ").map(&:to_i)
count_hash = {}

no_participations.each do |p|
  count_hash[p] ||= 0
  count_hash[p] += 1
end
res = 0
(0..5-k).each do |i|
  res += count_hash[i] if count_hash[i]
end
puts res / 3

n, k = gets.split.map(&:to_i)
a = gets.split.map(&:to_i).sort
c = 0
a.each do |x|
  c += 1 if x + k <= 5
end
puts c / 3

n, k = gets.split.map(&:to_i)
puts gets.split.map(&:to_i).count{|x| x + k <= 5} / 3

n, k = gets.split(' ').map(&:to_i)
a = gets.split(' ').map(&:to_i)

puts(a.select { |x| x <= 5-k }.size.div(3))

i=->{gets.split.map(&:to_i)}
_,k=i[]
p i[].select{|x|x<6-k}.size/3

#!/usr/bin/ruby

class Solver
    def solve()
        ans = 0
        n, k = STDIN.gets.split(" ").map(&:to_i)
        times = STDIN.gets.split(" ").map(&:to_i)
        times.sort!
        i = 0
        while i <= times.length - 3
            a = times[i]
            b = times[i+1]
            c = times[i+2]
            max = [a, b, c].max
            if max + k <= 5
                ans += 1
            end
            i += 2
        end

        puts ans
    end
end

Solver.new.solve()

n = gets.chomp
n = n.split
number_of_participants = n[0].to_i
times_needed = n[1].to_i
part = gets.chomp
participated = part.split

possible_teams = number_of_participants/3
count = 0
for i in (0..number_of_participants-1)
	if participated[i].to_i + times_needed <= 5
		count += 1
	end
end

if count >= 3
	puts possible_teams
else
	puts 0
end

n, k = gets.split.map(&:to_i)
a = gets.split.map(&:to_i).sort
c = 0
a.each do |x|
  c += 1 if x + k < 5
end
puts c / 3

i=->{gets.split.map(&:to_i)}
_,k=i[]
p i[].collect{|x|x<6-k}.size/3


class Result
  def initialize(score, order)
    @score = score
    @order = order
  end

  def score
    @score
  end

  def order
    @order
  end
end

def read_next_line
  gets.chomp.split.map(&:to_i)
end

n = gets.to_i
results = Array.new(2 * n)
(0...n).each { |i|
  r = read_next_line
  results[i] = Result.new(r[0], 0)
  results[i + n] = Result.new(r[1], 1)
}

results.sort_by! { |result| result.score }

winners_count = Array.new(2, 0)
(0...n).each { |i|
  winners_count[results[i].order] += 1
}

winners_count.each { |count|
  puts ('1' * [count, n / 2].max).ljust(n, '0')
}

# worst case: the first n (of both sf) advance;
# best case: the first n/2 of each semi-final;

n = gets.to_i
a = []
b = []
res = {'a'=>[], 'b'=>[]}
n.times do |i|
  ai,bi = gets.split.map(&:to_i)
  a << ai
  b << bi
end
(n/2...n).each do |i|
  res['a'] << (a[i] < b[n-i-1] ? '1' : '0')
  res['b'] << (b[i] < a[n-i-1] ? '1' : '0')
end
puts Array.new(n/2){'1'}.concat(res['a']).join
puts Array.new(n/2){'1'}.concat(res['b']).join


n, m = gets.chomp.split.map(&:to_i)
a = gets.chomp.split.map(&:to_i)
b = gets.chomp.split.map(&:to_i)
i = 0
j = 0
while i < n && j < m
  i += 1 if a[i] <= b[j]
  j += 1
end
puts n - i

# http://codeforces.com/problemset/problem/387/B
# Two pointers

n, m = gets.chomp.split.map(&:to_i)
a = gets.chomp.split.map(&:to_i)
b = gets.chomp.split.map(&:to_i)

i, j = 0, 0
count = 0

while i < n && j < m
  if a[i] <= b[j]
    i += 1
    count += 1
  end

  j += 1
end

puts n - count

def solve(req, actual)
  i, j, req_size, act_size = [0, 0, req.size, actual.size]
  while i < req_size
    while j < act_size && actual[j] < req[i]
      j += 1
    end
    break if j == act_size
    i += 1
    j += 1
  end
  req_size - i
end

if __FILE__ == $0
  def read_next_line
    gets.chomp.split.map(&:to_i)
  end

  gets
  puts solve(read_next_line, read_next_line)
end

def read_data
	s = gets.chomp
	s.split.map &:to_i
end

n,m = read_data
a = read_data
b = read_data

a.sort! { |x,y| y <=> x}
b.sort! { |x,y| y <=> x}

result = 0
index = 0

for k in a
	if b[index] && b[index] >= k
		index += 1
	else
		result += 1
	end
end

puts result

def checks(n_m, p1, p2)
  n_m = n_m.split.map(&:to_i)
  n = n_m[0]
  m = n_m[1]
  p1 = p1.split.map(&:to_i)
  p2 = p2.split.map(&:to_i)

  count = 0
  j = 0
  for i in (0..n - 1)
    for j in (j..m - 1)
      if p1[i] <= p2[j]
        count += 1
        j += 1
        break
      else
        j += 1
      end
    end
  end

  puts n - count
end

checks(gets, gets, gets)

n,m=gets.chomp.split.map(&:to_i)
a=gets.chomp.split.map(&:to_i)
b=gets.chomp.split.map(&:to_i)
i,j=0,0
while i<n && j<m
	i+=1 if a[i]<=b[j]
	j+=1
end
puts n-i

class ProblemA
  def initialize
    @dats = STDIN.read.split("\n")
    @n, @m = @dats[0].split(" ").map(&:to_i)
    @a_arr = @dats[1].split(" ").map(&:to_i) #need
    @b_arr = @dats[2].split(" ").map(&:to_i) #prepared
  end

  def solve
    i,j = [0, 0]
    j_memoize = nil

    need  = @a_arr.sort
    had   = @b_arr.sort
    max_touch = need.length

    while i < need.length && j < had.length do
      if need[i] <= had[j]
        max_touch -= 1
        i,j = i+1, j+1
        next
      else
        j = j+1
        next
      end
    end
    print max_touch
  end
end

solver = ProblemA.new
solver.solve

n,m=gets.chomp.split.collect{|a| a.to_i}
ns=gets.chomp.split.collect{|a| a.to_i}
ps=Hash.new(0)
gets.chomp.split.collect{|a| ps[a.to_i]+=1 }
next_hard=0
hardest=ps.keys.max
#p hardest
res=0
ns.each_index do |i|
 if next_hard<=ns[i]
   next_hard=ns[i]+1
 end
   if ps[ns[i]] == 0
#      puts i,next_hard,ps[next_hard]
      while next_hard <= hardest && ps[next_hard] == 0
        next_hard+=1
      end
 #     puts next_hard
 #     puts "saaaaaaaaaaa"
      if next_hard > hardest
         res+=1
      else
         ps[next_hard]-=1
      end
   end
end
#puts "sssssssssssS"
puts res

def binSearch(find_in, left, right, value_to_find)
    best = -1

    while left <= right
        mid = (left + right) / 2

        if find_in[mid].to_i >= value_to_find
            best = mid
            right = mid - 1
        else
            left = mid + 1
        end

    end

    return best
end

n_m = gets.chomp.split(/ /)
n = n_m[0].to_i
m = n_m[1].to_i

to_find = gets.chomp.split(/ /)
find_in = gets.chomp.split(/ /)
extra = 0

to_find.each do |i|
    pos = binSearch(find_in, 0, m - 1, i.to_i)

    if pos == -1
        extra += 1
    else
        for j in pos..m - 1 do
            find_in[j] = find_in[j + 1]
        end
        m -= 1
    end
end

puts extra

n,m = gets.split(" ").map(&:to_i)
comp = gets.split(" ").map(&:to_i)
arr = gets.split(" ").map(&:to_i)

dummy = Hash.new(0)
arr.each do |a|
	dummy[a] += 1
end
ans = 0
count = {}.merge!(dummy)
# puts "#{count}"
comp.each do |c|
	key = c if count[c] && count[c] != 0
	key ||= count.keys.detect{|x|  x > c && count[x] != 0}
	# puts "key #{key}"
	if key
		count[key] -= 1
	else
		ans += 1
	end
end

puts ans

def checks(n_m, p1, p2)
  n_m = n_m.split.map(&:to_i)
  n = n_m[0]
  m = n_m[1]
  p1 = p1.split.map(&:to_i)
  p2 = p2.split.map(&:to_i)

  count = 0
  for i in (0..n - 1)
    for j in (0..m - 1)
      if p1[i] <= p2[j]
        count += 1
        break
      end
    end
  end

  puts n - count
end

checks(gets, gets, gets)

def checks(n_m, p1, p2)
  n_m = n_m.split.map(&:to_i)
  n = n_m[0]
  m = n_m[1]
  p1 = p1.split.map(&:to_i).uniq
  p2 = p2.split.map(&:to_i)

  count = p1.size
  for i in (0..n - 1)
    for j in (0..m - 1)
      if p1[i] == p2[j]
        count -= 1
        break
      end
    end
  end
  if [0, 2, 3].include? count
    puts count
  else
    puts count
    puts p2
  end
end

checks(gets, gets, gets)

def checks(n_m, p1, p2)
  n_m = n_m.split.map(&:to_i)
  n = n_m[0]
  m = n_m[1]
  p1 = p1.split.map(&:to_i)
  p2 = p2.split.map(&:to_i)

  count = 0
  for i in (0..n - 1)
    for j in (0..m - 1)
      if p1[i] != p2[j]
        count += 1
        break
      end
    end
  end

  puts n - count
end

checks(gets, gets, gets)

def checks(n_m, p1, p2)
  n_m = n_m.split.map(&:to_i)
  n = n_m[0]
  m = n_m[1]
  p1 = p1.split.map(&:to_i).uniq
  p2 = p2.split.map(&:to_i)

  count = p1.size
  for i in (0..n - 1)
    for j in (0..m - 1)
      if p1[i] != p2[j]
        count += 1
        break
      end
    end
  end

  puts n - count
end

checks(gets, gets, gets)

def checks(n_m, p1, p2)
  n_m = n_m.split.map(&:to_i)
  n = n_m[0]
  m = n_m[1]
  p1 = p1.split.map(&:to_i)
  p2 = p2.split.map(&:to_i)

  count = 0
  for i in (0..n - 1)
    for j in (0..m - 1)
      if p1[i] == p2[j]
        count += 1
        break
      end
    end
  end

  puts n - count
end

checks(gets, gets, gets)

def checks(n_m, p1, p2)
  n_m = n_m.split.map(&:to_i)
  n = n_m[0]
  m = n_m[1]
  p1 = p1.split.map(&:to_i).uniq
  p2 = p2.split.map(&:to_i).uniq

  count = n
  for i in (0..n - 1)
    for j in (0..m - 1)
      if p1[i] == p2[j]
        count -= 1
        break
      end
    end
  end

  puts count
end

checks(gets, gets, gets)

def checks(n_m, p1, p2)
  n_m = n_m.split.map(&:to_i)
  n = n_m[0]
  m = n_m[1]
  p1 = p1.split.map(&:to_i).uniq
  p2 = p2.split.map(&:to_i).uniq

  count = p1.size
  for i in (0..n - 1)
    for j in (0..m - 1)
      if p1[i] == p2[j]
        count -= 1
        break
      end
    end
  end
  if [0, 2, 3].include? count
    puts count
  else
    puts p2
  end
end

checks(gets, gets, gets)

def checks(n_m, p1, p2)
  n_m = n_m.split.map(&:to_i)
  n = n_m[0]
  m = n_m[1]
  p1 = p1.split.map(&:to_i).uniq
  p2 = p2.split.map(&:to_i).uniq

  count = p1.size
  for i in (0..n - 1)
    for j in (0..m - 1)
      if p1[i] == p2[j]
        count -= 1
        break
      end
    end
  end

  puts count
end

checks(gets, gets, gets)

def checks(n_m, p1, p2)
  n_m = n_m.split.map(&:to_i)
  n = n_m[0]
  m = n_m[1]
  p1 = p1.split.map(&:to_i)
  p2 = p2.split.map(&:to_i)

  count = n
  for i in (0..n - 1)
    for j in (0..m - 1)
      if p1[i] == p2[j]
        count -= 1
        break
      end
    end
  end

  puts count
end

checks(gets, gets, gets)

def checks(n_m, p1, p2)
  n_m = n_m.split.map(&:to_i)
  n = n_m[0]
  m = n_m[1]
  p1 = p1.split.map(&:to_i)
  p2 = p2.split.map(&:to_i)

  count = 0
  for i in (0..n - 1)
    for j in (0..m - 1)
      if p1[i] <= p2[j]
        count += 1
        j += 1
        break
      else
        j += 1
      end
    end
  end

  puts n - count
end

checks(gets, gets, gets)

class ProblemA
  def initialize
    @dats = STDIN.read.split("\n")
    @n, @m = @dats[0].split(" ").map(&:to_i)
    @a_arr = @dats[1].split(" ").map(&:to_i) #need
    @b_arr = @dats[2].split(" ").map(&:to_i) #prepared
  end

  def solve
    i,j = [0, 0]
    j_memoize = nil

    need  = @a_arr
    had   = @b_arr
    max_touch = need.length

    while i < need.length && j < had.length do
      if need[i] == had[j]
        max_touch -= 1
        i,j = i+1, j+1
        next
      elsif need[i] < had[j]
        i = i+1
        next
      else
        j = j+1
        next
      end
    end
    print max_touch
  end
end

solver = ProblemA.new
solver.solve

n,m=gets.chomp.split.collect{|a| a.to_i}
ns=gets.chomp.split.collect{|a| a.to_i}
ps=Hash.new(0)
gets.chomp.split.collect{|a| ps[a.to_i]+=1 }
next_hard=0
res=0
for i in 0..n-1
 if next_hard<=ns[i]
   next_hard=ns[i]+1
 end
   if ps[ns[i]] == 0
      while next_hard < n && ps[next_hard] == 0
        next_hard+=1
      end
      if next_hard >= n
         res+=1
      else
         ps[next_hard]-=1
      end
   end
end

puts res

n,m=gets.chomp.split.collect{|a| a.to_i}
ns=gets.chomp.split.collect{|a| a.to_i}
ps=Hash.new(0)
gets.chomp.split.collect{|a| ps[a.to_i]+=1 }
next_hard=0
hardest=ps.keys.max
res=0
ns.each_index do |i|
 if next_hard<=ns[i]
   next_hard=ns[i]+1
 end
   if ps[ns[i]] == 0
#      puts i,next_hard
      while next_hard <= n && ps[next_hard] == 0
        next_hard+=1
      end
#      puts next_hard
 #     puts "saaaaaaaaaaa"
      if next_hard > hardest
         res+=1
      else
         ps[next_hard]-=1
      end
   end
end
#puts "sssssssssssS"
puts res

n,m=gets.chomp.split.collect{|a| a.to_i}
ns=gets.chomp.split.collect{|a| a.to_i}
ps=Hash.new(0)
gets.chomp.split.collect{|a| ps[a.to_i]+=1 }
next_hard=0
res=0
for i in 0..n-1
 if next_hard<=ns[i]
   next_hard=ns[i]+1
 end
   if ps[ns[i]] == 0
 #     puts i,next_hard
      while next_hard <= n && ps[next_hard] == 0
        next_hard+=1
      end
 #     puts next_hard
#      puts "saaaaaaaaaaa"
      if next_hard > n
         res+=1
      else
         ps[next_hard]-=1
      end
   end
end
#puts "sssssssssssS"
puts res

n_m_s = gets.chomp
n_m_a = n_m_s.split(/ /)

to_find_s = gets.chomp
to_find_a = to_find_s.split(/ /)

find_in_s = gets.chomp
find_in_a = find_in_s.split(/ /)

hash = Hash.new(0)

find_in_a.each do |i|
    hash[i] += 1
end

extra = 0

to_find_a.each do |i|
    hash[i] -= 1
    if hash[i] < 0
        hash[i] = 0
        extra += 1
    end
end

puts extra

n,m = gets.split(" ").map(&:to_i)
comp = gets.split(" ").map(&:to_i)
arr = gets.split(" ").map(&:to_i)

dummy = Hash.new(0)
arr.each do |a|
	dummy[a] += 1
end
ans = 0
count = {}.merge!(dummy)
# puts "#{count}"
comp.each do |c|
	key = c if count[c]
	key ||= count.keys.detect{|x|  x > c && count[x] != 0}
	# puts "key #{key}"
	if key
		count[key] -= 1
	else
		ans += 1
	end
end

puts ans

# http://codeforces.com/problemset/problem/387/B
# Two pointers

n, m = gets.chomp.split.map(&:to_i)
a = gets.chomp.split.map(&:to_i)
b = gets.chomp.split.map(&:to_i)
count = 0

for i in 0..(n - 1)
  for j in 0..(m - 1)
    if a[i] == b[j]
      count += 1
      break
    end
  end
end

puts n - count

# http://codeforces.com/problemset/problem/387/B
# Two pointers

n, m = gets.chomp.split.map(&:to_i)
a = gets.chomp.split.map(&:to_i)
b = gets.chomp.split.map(&:to_i)

i, j = 0, 0
count = 0

while i < n && j < m
  if b[j] == a[i]
    count += 1
    i += 1
    j += 1
  elsif b[j] > a[i]
    i += 1
  else
    j += 1
  end
end

puts n - count


MOD=10**9+7
cnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)
def gs() gets.chomp end
def gi() gets.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def desc(ar) ar.sort!{|x,y|y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+) end

def C(a,b) b==0||a==b ? 1 : (b=a-b if a/2<b;(a-b+1..a).inject(:*)/(1..b).inject(:*)) end

def puts_yesno(can) puts(can ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def debug(k,v) puts "#{k}:#{v}" end
########### ( ˘ω˘ )ｽﾔｧ… ###########
q=gi
q.times do
  aa=gsmi.sort
  diff = aa[2]-aa[0]
  if diff<=1
    puts 0
  else
    aa[2]-=1
    aa[0]+=1
    d = 2*(aa[2]-aa[0])
    puts d
  end
end

gets.to_i.times do
	a = gets.split.map(&:to_i)
	puts [-1, 0, 1].repeated_permutation(3).map { |perm|
			a.zip(perm).map { _1 + _2 }.combination(2).sum { (_1 - _2).abs }
	     }.min
end


Alphabet = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
used = {}
n,k = gets.split.map(&:to_i)
for i in 0...k
	used[Alphabet[i]] = 0
end

s = gets.chomp.split('')

for char in s
	used[char] += 1
end

puts used.values.min * k

n,k=gets.strip.split.map(&:to_i)
str = gets.strip

ary = Array.new(k, 0)
hsh = {}
i = 0
('A'..'Z').to_a.each do |c|
  hsh[c]=i
  i+=1
end

str.each_char do |c|
  ary[hsh[c]] += 1
end

puts ary.min * k

n, k = gets.split.map(&:to_i)
s = gets.chomp.chars

cnt = Array.new(k, 0)

s.each do |ss|
  cnt[('A'..'Z').to_a.index(ss)] += 1
end

puts cnt.min * k

n, k = gets.split.map &:to_i
m = {}
('A'..'Z').to_a[0...k].each { |x| m[x] = 0 }
gets.strip.split('').each { |x| m[x] += 1 }
l = m['A']
m.each { |key, value| l = [l, value].min }
puts l*k

nk = gets.split(" ").map(&:to_i)
str = gets.chomp

n = nk[0]
k = nk[1]

hash = Hash.new(0)
str.each_char do |ch|
  hash[ch]+=1
end

if hash.keys.length < k
  puts 0
else
  puts hash.values.min*k
end


gets.to_i.times do
  n=gets.to_i
  a=gets.split.map(&:to_i)
  c=0
  q=0
  m=0
  a.each do |aa|
    if aa!=q
      m=c if c>m
      c=1
      q=aa
    else
      c+=1
    end
  end
  m=c if c>m
  puts m
end

t = gets.to_i
t.times do
  n = gets.to_i
  a = gets.split.map {|x| x.to_i }
  puts a.map { |x| a.count(x) }.max
end


# coding: utf-8
n = gets.to_i
map = n.times.map {|i|
  gets.chomp.chars.map{|c|
    c == "."
  }.each_with_index.map{|c, j|
    [i.next, j.next, c]
  }
}
check  = proc {|line| line.any?(&:last) }
answer = proc {|line| puts line.find(&:last).first(2).join " " }
if map.all?(&check)
  map.each(&answer)
elsif map.transpose.all?(&check)
  map.transpose.each(&answer)
else
  puts -1
end

n=gets.to_i
m=[]
f=false
n.times do
  m << gets.chomp.split('')
  f=true if !m.last.include?('.')
end
m=m.transpose if f
f2=false
m.each {|x| f2=true if !x.include?('.')}
if f and f2
  puts -1
  exit
end
m.each_with_index do |x,i|
  a=x.index('.')+1
  b=i+1
  if f
    puts "#{a} #{b}"
  else
    puts "#{b} #{a}"
  end
end

#!/usr/bin/env ruby
def cal_purify(pos, vis, n)
  num = 0
  num += 1 if !vis[pos[0]][pos[1]]
  for i in 1..n
    num += 1 if pos[0] - i >= 0 && !vis[pos[0] - i][pos[1]]
    num += 1 if pos[0] + i < n && !vis[pos[0] + i][pos[1]]
    num += 1 if pos[1] - i >= 0 && !vis[pos[0]][pos[1] - i]
    num += 1 if pos[1] + i < n && !vis[pos[0]][pos[1] + i]
  end
  return num
end

def purify(pos, vis, n)
  vis[pos[0]][pos[1]] = true
  for i in 1..n
    vis[pos[0] - i][pos[1]] = true if pos[0] - i >= 0
    vis[pos[0] + i][pos[1]] = true if pos[0] + i < n
    vis[pos[0]][pos[1] - i] = true if pos[1] - i >= 0
    vis[pos[0]][pos[1] + i] = true if pos[1] + i < n
  end
end
n = gets.to_i
map = []
n.times do
  map << gets.chomp!
end
can_purify = []
for i in 0...map.size
  for j in 0...map[i].size
    if map[i][j] != 'E'
      can_purify << [i, j]
    end
  end
end
rowvis = Array.new(n + 1, false)
colvis = Array.new(n + 1, false)
rowcnt = colcnt = 0
can_purify.each do |pos|
  if !rowvis[pos[0]]
    rowcnt += 1
    rowvis[pos[0]] = true
  end
  if !colvis[pos[1]]
    colcnt += 1
    colvis[pos[1]] = true
  end
end
result = []
vis = Array.new(n + 1, false)
if rowcnt == n
  can_purify.each do |pos|
    if !vis[pos[0]]
      result << pos
      vis[pos[0]] = true
    end
  end
elsif colcnt == n
  can_purify.each do |pos|
    if !vis[pos[1]]
      result << pos
      vis[pos[1]] = true
    end
  end
end
if result.size != n
  puts "-1"
else
  result.each do |step|
    step[0] += 1
    step[1] += 1
    puts step.join(' ')
  end
end

#!/usr/bin/env ruby
n = gets.to_i
map, can_purify = [], []
n.times do
  map << gets.chomp!
end
for i in 0...map.size
  for j in 0...map[i].size
    can_purify << [i, j] if map[i][j] != 'E'
  end
end
rowvis, colvis = Array.new(n + 1, false), Array.new(n + 1, false)
rowcnt = colcnt = 0
can_purify.each do |pos|
  rowvis[pos[0]] = true if !rowvis[pos[0]]
  colvis[pos[1]] = true if !colvis[pos[1]]
end
result = []
vis = Array.new(n + 1, false)
if rowvis.count(true) == n
  can_purify.each do |pos|
    next if result.include? pos[0]
    puts "#{pos[0] + 1} #{pos[1] + 1}"
    result << pos[0]
  end
elsif colvis.count(true) == n
  can_purify.each do |pos|
    next if result.include? pos[1]
    puts "#{pos[0] + 1} #{pos[1] + 1}"
    result << pos[1]
  end
else
  puts "-1"
end

#!/usr/bin/env ruby
n = gets.to_i
map = []
n.times do
  map << gets.chomp!
end
can_purify = []
for i in 0...map.size
  for j in 0...map[i].size
    if map[i][j] != 'E'
      can_purify << [i, j]
    end
  end
end
rowvis = Array.new(n + 1, false)
colvis = Array.new(n + 1, false)
rowcnt = colcnt = 0
can_purify.each do |pos|
  if !rowvis[pos[0]]
    rowcnt += 1
    rowvis[pos[0]] = true
  end
  if !colvis[pos[1]]
    colcnt += 1
    colvis[pos[1]] = true
  end
end
result = []
vis = Array.new(n + 1, false)
if rowcnt == n
  can_purify.each do |pos|
    if !vis[pos[0]]
      result << pos
      vis[pos[0]] = true
    end
  end
elsif colcnt == n
  can_purify.each do |pos|
    if !vis[pos[1]]
      result << pos
      vis[pos[1]] = true
    end
  end
end
if result.size != n
  puts "-1"
else
  result.each do |step|
    step[0] += 1
    step[1] += 1
    puts step.join(' ')
  end
end

n=gets.to_i
s=[]
n.times { s<<gets.chomp.each_char.map{ |v| v==?E ? 1 : 0 } }
rows=[]
s.each_with_index { |v, i|
    k=v.index(0)
    rows<<[i+1, k+1] if k
}

cols=[]
0.upto(n-1) { |j|
    0.upto(n-1) { |i|
        if s[i][j]==0
            cols<<[i+1, j+1]
            break
        end
    }
}

if rows.size==n
    rows.each { |v| puts v*' ' }
elsif cols.size==n
    cols.each { |v| puts v*' ' }
else
    p -1
end

n = gets.to_i
s = Array.new(n)
n.times{|i| s[i] = gets.chomp.split("")}
ans = Array.new
n.times do |i|
    ans.push(s[i].index(".")) if s[i].index(".")
end
if ans.size >= n
    n.times{|i| puts [i+1, ans[i]+1].join(" ")}
    exit
end
ans.clear
s = s.transpose
n.times do |i|
    ans.push(s[i].index(".")) if s[i].index(".")
end
if ans.size >= n
    n.times{|i| puts [ans[i]+1, i+1].join(" ")}
    exit
end
puts "-1"

n = gets.to_i
a = Array.new(n).map! { gets.chomp.split(//) }
b = a.transpose

def can(a)
    a.each do |e|
        return false if e.count('.') == 0
    end
    true
end

if can(a)
    a.each_with_index do |e, i|
        puts "#{i+1} #{e.index('.')+1}"
    end
elsif can(b)
    b.each_with_index do |e, i|
        puts "#{e.index('.')+1} #{i+1}"
    end
else
    puts -1
end

n = gets.to_i
a = Array.new(n).map! { gets.chomp.split(//) }
b = a.transpose
# puts a.inspect

def can(a)
    a.each do |e|
        return false if e.count('.') == 0
    end
    true
end

if can(a)
    a.each_index do |i|
        puts "#{i+1} #{a[i].index('.')+1}"
    end
elsif can(b)
    b.each_index do |i|
        puts "#{b[i].index('.')+1} #{i+1}"
    end
else
    puts -1
end

n = gets.to_i
a = Array.new(n).map! { gets.chomp.split(//) }
b = a.transpose
# puts a.inspect

def can(a)
    a.each do |e|
        return false if e.count('.') == 0
    end
    true
end

if can(a)
    a.each_index do |i|
        puts "#{i+1} #{a[i]}.index('.')+1}"
    end
elsif can(b)
    b.each_index do |i|
        puts "#{b[i].index('.')+1} #{i+1}"
    end
else
    puts -1
end

n = gets.to_i
a = Array.new(n).map! { gets.chomp.split(//) }
b = a.transpose
# puts a.inspect

def can(a)
    a.each do |e|
        return false if e.count('.') == 0
    end
    true
end

if can(a)
    a.each_index do |i|
        puts "#{i} #{a[i].index('.')}"
    end
elsif can(b)
    b.each_index do |i|
        puts "#{b[i].index('.')} #{i}"
    end
else
    puts -1
end

n = gets.to_i
s = Array.new(n)
n.times{|i| s[i] = gets.chomp.split("")}
ans = Array.new
n.times do |i|
    ans.push(s[i].index(".")) if s[i].index(".")
end
if ans.size >= n
    n.times{|i| puts [i+1, ans[i]+1].join(" ")}
    exit
end
ans.clear
s = s.transpose
n.times do |i|
    ans.push(s[i].index(".")) if s[i].index(".")
end
if ans.size >= n
    n.times{|i| puts [i+1, ans[i]+1].join(" ")}
    exit
end
puts "-1"

n = gets.to_i
s = Array.new(n)
n.times{|i| s[i] = gets.chomp.split("")}
ans = Array.new
n.times do |i|
    ans.push(s[i].index(".")) if s[i].index(".")
end
if ans.size >= n
    n.times{|i| puts [i+1, ans[i]+1].join(" ")}
    exit
end
ans.clear
s.transpose
n.times do |i|
    ans.push(s[i].index(".")) if s[i].index(".")
end
if ans.size >= n
    n.times{|i| puts [i+1, ans[i]+1].join(" ")}
    exit
end
puts "-1"

n=gets.to_i
ok=true
res=[]
1.upto(n) {|i|
    s=gets.chomp
    k=s.index(?.)
    if k
        res<<[i, k+1]
    else
        ok=false
    end
}
if ok
    res.each {|v|
        puts v*' '
    }
else
    p -1
end

n = gets.to_i
map = n.times.map {|i| gets.chomp.chars.to_a }
check = proc {|line| line.include? "." }
write = proc {|line, i|
  safe = line.each_with_index.find{|cell| cell.first == "." }
  puts [i.next, safe.last.next].join ' '
}
puts map.inspect,map.transpose.inspect
if map.all?(&check)
  map.each_with_index(&write)
elsif map.transpose.all?(&check)
  map.transpose.each_with_index(&write)
else
  puts -1
end

n = gets.to_i
map = n.times.map {|i| gets.chomp.chars.to_a }
check = proc {|line| line.include? "." }
write = proc {|line, i|
  safe = line.each_with_index.find{|cell| cell.first == "." }
  puts [i.next, safe.last.next].join ' '
}
if map.all?(&check)
  map.each_with_index(&write)
elsif map.transpose.all?(&check)
  map.transpose.each_with_index(&write)
else
  puts -1
end


steps = gets.chomp.to_i
movement = gets.chomp

coordinate_movements = [[0, 0]]

for i in 0...steps
  if movement[i] == 'U'
    coordinate_movements << [coordinate_movements[coordinate_movements.count - 1][0], coordinate_movements[coordinate_movements.count - 1][1] + 1]
  else
    coordinate_movements << [coordinate_movements[coordinate_movements.count - 1][0] + 1, coordinate_movements[coordinate_movements.count - 1][1]]
  end
end

payment = 0

if coordinate_movements.count > 2
  for i in 2...coordinate_movements.count
    if coordinate_movements[i-1][0] == coordinate_movements[i-1][1]
      payment += 1 if ((coordinate_movements[i - 2][0] == coordinate_movements[i][0]) && (coordinate_movements[i][1] - coordinate_movements[i - 2][1] == 2)) || ((coordinate_movements[i - 2][1] == coordinate_movements[i][1]) && (coordinate_movements[i][0] - coordinate_movements[i - 2][0] == 2))
    end
  end
end

puts payment


gets
a = gets.split.map(&:to_i)
b = a.min
p a.map{|i| i % b}.max == 0 ? b : -1

N = gets.chomp.to_i
A = gets.chomp.split(' ').map{|c| c.to_i}
m = A.min
# puts m
A.each do |c|
	if c%m != 0
		puts "-1"
		exit
	end
end
puts m

n = gets.to_i
a = gets.split(' ').map { |i| i.to_i }.sort
can = true
for i in 1...a.size
    can = false if a[i] % a[0] != 0
end
puts can ? a[0] : -1

def run
  n = $stdin.gets
  a = $stdin.gets.split.map(&:to_i)
  a.sort!

  f = true
  a.each do |x|
    f = false if x % a.first != 0
  end

  puts f ? a.first : -1
end

run if $0 == __FILE__

class A
  def initialize
    n = $stdin.gets.chomp.to_i
    array = $stdin.gets.chomp.split(' ').map(&:to_i)

    ans = array[0]

    array.each do |num|
      ans = ans.gcd(num)
    end

    if ans == 1 && !array.include?(1)
      puts -1
    elsif array.include?(ans)
      puts ans
    else
      puts -1
    end
  end
end

a = A.new

def main()
	n=gets.chomp.to_i
	ar=gets.chomp.split(" ")
	ar=ar.map{|i| i.to_i}
	if n==1
		puts ar[0]
		return
	end
	gcd=getGcd(ar[0],ar[1])
	for i in 2...n
		gcd=getGcd(gcd,ar[i])
	end
	if ar.include?(gcd)
		puts gcd
	else
		puts "-1"
	end
end
def getGcd(a,b)
	if(a==0 || b==0)
		return a+b
	end
	return getGcd(b,a%b)
end
main()

def ksuha(input)
  min_ele = input.min
  if min_ele == 1
    return min_ele
  else
    return min_ele if check(input, min_ele)
    -1
  end
end

def check(input, min_elem)
  input.all? { |i| i%min_elem == 0 }
end

_ = STDIN.gets
input = STDIN.readline.split(" ").map(&:to_i)

puts ksuha(input)

n = gets.to_i
as = gets.split.map(&:to_i)
g = as.inject(0) { |g, a| g.gcd(a) }
as.each do |a|
  if g % a == 0
    puts a
    exit 0
  end
end
puts -1

def gcd(a, b)
  if b == 0
    a
  else
    gcd(b, a % b)
  end
end

n = gets[0..-2].to_i
a = gets[0..-2].split(' ').collect{|x| x.to_i}
if n == 1
  print a[0]
else
  uc = a[0]
  a.each{|x| uc = gcd(uc, x)}
  ok = false
  a.each do |x|
    if uc % x == 0
      ok = true
      print x
      break
    end
  end
  print -1 unless ok
end

gets
a = gets.split.map(&:to_i)
m = a.min
a.each do |i|
	if i % m != 0
		puts -1
		exit 0
	end
end
puts m

at_exit do
  n = get_numbers_from_line[0]
  as = get_numbers_from_line[0...n]
  num = as.min
  if as.all?{|x| x % num == 0}
    puts num
  else
    puts '-1'
  end

end

def get_numbers_from_line
  gets.strip.split.map(&:to_i)
end

n = gets().to_i
a = gets().split(' ').map { |p| p.to_i}
num = a.min
div = true
for x in a
        if x%num != 0
                div = false
                break
        end
end

if div
        puts num
else
        puts -1
end

class A
  def initialize
    n = $stdin.gets.chomp.to_i
    array = $stdin.gets.chomp.split(' ').map(&:to_i)

    ans = array[0]

    array.each do |num|
      ans = ans.gcd(num)
    end

    if ans == 1 && !array.include?(1)
      puts -1
    else
      puts ans
    end
  end
end

a = A.new

def main()
	n=gets.chomp.to_i
	ar=gets.chomp.split(" ")
	ar=ar.map{|i| i.to_i}
	gcd=getGcd(ar[0],ar[1])
	for i in 2...n
		gcd=getGcd(gcd,ar[i])
	end
	puts gcd
end
def getGcd(a,b)
	if(a==0 || b==0)
		return a+b
	end
	return getGcd(b,a%b)
end
main()

def gcd(a, b)
  if b == 0
    a
  else
    gcd(b, a % b)
  end
end

n = gets[1..-1].to_i
a = gets[1..-1].split(' ').collect{|x| x.to_i}
if n == 1
  print a[0]
else
  uc = a[0]
  a.each{|x| uc = gcd(uc, x)}
  ok = false
  a.each do |x|
    if uc % x == 0
      ok = true
      print x
      break
    end
  end
  print -1 unless ok
end

n = gets().to_i
a = gets().split(' ').map { |p| p.to_i}
num = a.min
div = true
for x in a
        if x%num != 0
                puts " #{x} #{num}"
                div = false
                break
        end
end

if div
        puts num
else
        puts -1
end


n = gets.to_i
home_games = (n-1)
total_games = (n-1) * 2
home = []
away = []
home_count = Hash.new(0)
n.times do
	h,a = gets.split(" ").map(&:to_i)
	home << h
	home_count[h] += 1
	away << a
end
ans_count = []
n.times do |i|
	ans_count << home_games + home_count[away[i]]
end

ans_count.each do |a|
	puts "#{a} #{total_games - a}"
end

n=gets.to_i
a,b,xu=[],[],Array.new(100001,0)
n.times do |i|
	x,y=gets.chomp.split.map(&:to_i)
	a<<x
	b<<y
	xu[x]+=1
end
n.times { |i| puts "#{n-1+xu[b[i]]} #{n-1-xu[b[i]]}" }

n = gets.to_i
h = [0] * 100001
a = Array.new(n + 1)
for i in 1..n
  y = gets.split(" ").collect {|x| x.to_i}
  h[y[0]] += 1
  a[i] = y[1]
end
for i in 1..n
  printf("%d %d\n", n - 1 + h[a[i]], n - 1 - h[a[i]])
end