n, p = gets.split(/\s+/).map(&:to_i)
s = gets.strip

def get_next(s, n, p)
  if n == 1
    if s[0].ord == p.ord
      nil
    else
      s[0].succ
    end
  else
    q = s[-1] == 'z' ? '{' : s[-1].succ
    x = s[0...-1]
    begin
      while q.ord <= p.ord && (q == x[-1] || q == x[-2])
        q = q == 'z' ? '{' : q.succ
      end

      if q.ord <= p.ord
        return "#{x}#{q}"
      else
        x = get_next(x, n-1, p)
        q = 'a'
      end
    end while x

    nil
  end
end

p = ('a'.ord + p.ord-1).chr

if (s = get_next(s, n, p))
  puts s
else
  puts "NO"
end

def fill_string(string, i, max_ord)
  (i...string.size).each do |i|
    ('a'.ord..max_ord).each { |j|
      if (i-1<0 || j.chr != string[i-1]) && (i-2<0 || j.chr != string[i-2])
        string[i] = j.chr
        break
      end
    }
  end
  string
end

p = gets.split[1].to_i + 'a'.ord - 1
string = gets[0..-2]
no = true
(0...string.size).reverse_each do |i|
  (string[i].ord+1..p).each do |j|
    if (i-1<0 || j.chr != string[i-1]) && (i-2<0 || j.chr != string[i-2])
      string[i] = j.chr
      puts fill_string string, i+1, p
      no = false
      break
    end
  end
  break unless no
end

puts "NO" if no


a=gets.chomp.split(" ").map{|i| i.to_i}
b=gets.chomp.split(" ")

maxind=0
z=0
max=0
p=0
sq=0

if a[1]>0
0.upto(a[0]-1) do |i|

	if i>0
	sq=sq-1
	if b[i-1]=="0"
	z=z-1
	else
	z=z
	end
	end

  loop do
    break if p>=a[0]
    if b[p]=="0"
        z+=1
    end
	break if z>a[1]
        sq+=1
		p+=1
    end
     z-=1
    if sq>max
        max=sq
        maxind=i
    end

	break if p==a[0]
end
   k=0
loop do
	break if maxind==a[0]
	break if k==a[1]
    if b[maxind]=="0"
        b[maxind]="1"
        k+=1
    end
	 maxind +=1
end
puts "#{max}"
puts b.join(" ")

else

sq=0
b.each do |i|
if i== "0"
if sq>max
max=sq
end
sq=0
else
sq+=1
end
end
if sq>max
max=sq
end
puts "#{max}"
puts b.join(" ")

end

buf=gets.split(' ')
n,k=buf[0].to_i, buf[1].to_i
t=k
a=gets.split(' ')
r=ma=st=0
for l in 0..n-1
	k+=1 if l>0 && a[l-1]=='0'
	while r<n && (a[r]=='1' || k>0)
		k-=1 if a[r]=='0'
		r+=1
	end
	ma,st=r-l,l if r-l>ma
end
puts ma
while st<n && t>=0
	break if t<1 && a[st]==?0
	t-=1 if a[st]==?0
	a[st]=?1
	st+=1
end
puts a*" "

a=gets.chomp.split(" ").map{|i| i.to_i}
b=gets.chomp.split(" ")
maxind=0
max=0
0.upto(a[0]-2) do |i|
	p=0
    p=i
    sq=0
    z=0
    loop do
    if b[p]=="0"
        z+=1
    end
       p+=1
	break if p==a[0]
    break if z>a[1]
        sq+=1
    end
    if sq>max
        max=sq
        maxind=i
    end
end

k=0
loop do
    if b[maxind]=="0"
        b[maxind]="1"
        k+=1
    end
	 maxind +=1

    break if k==a[1]
end
puts "#{max}"
puts b.join(" ")


k = gets.to_i
k.times do
  n = gets.to_i
  as = gets.split.map(&:to_i).sort.reverse
  ans = 0
  as.each_with_index do |a, i|
    if a > ans
      ans += 1
    end
  end
  puts ans
end

def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def sum(a) a.inject(:+) end

q = inp[0]
q.times do
  n = inp[0]
  t = inp
  t.sort!.reverse!
  ans = 0
  n.times do |i|
    ans = [ans,[t[i],(i+1)].min].max
  end
  p ans
end

g = gets.chomp.to_i
g.times{
n = gets.to_i
max = 0
doski = gets.split(" ").map{|x|x.to_i}
jj = (1...1001).to_a
jj.map{|w|
q=0
doski.map{|e| if e >= w then q+=1 end}
if q >= w and max < w then max =  w end
}
puts max
}

g = gets.chomp.to_i
g.times{
n = gets.to_i
max = 0
doski = gets.split(" ").map{|x|x.to_i}
jj = (1...1000).to_a
jj.map{|w|
q=0
doski.map{|e| if e >= w then q+=1 end}
if q >= w and max < w then max =  w end
}
puts max
}


ans,a=0,Array.new(100,0)
gets.to_i.times do |i|
	l,r=gets.chomp.split.map(&:to_i)
	for j in l...r
		a[j]=i==0
	end
end
puts a.count(true)

n = gets.to_i
alex_l,alex_r = gets.split(" ").map(&:to_i)

# (n-1).times do
# 	l,r = gets.split(" ").map(&:to_i)
# 	x,y = l+1,r-1
# 	# x,y = y,x if x > y
# 	if l + 1 == r
# 		# puts "here"
# 		alex -= [l]
# 	else
# 		alex -= (x..y).to_a
# 	end
# end
# length = 0
# (1..alex.length-1).each do |i|
# 	if (alex[i-1] + 1 == alex[i]) || (alex[i+1] && alex[i]+1 != alex[i+1])
# 		puts alex[i]
# 		length += 1
# 	end
# end
# puts "#{alex}"
# puts length
used = Array.new(100,true)

(n-1).times do
	l,r = gets.split(" ").map(&:to_i)
	(l..r-1).each do |i|
		used[i] = false
	end
end
puts "#{used[alex_l..alex_r-1].count(true)}"

class Array
	def f x
		self[0] - 1 < x && x < self[1]
	end
end

n = gets.to_i
l, r = gets.split.map(&:to_i)
seg = []
(n-1).times{seg<<gets.split.map(&:to_i)}
tot = 0
l.upto(r-1){|i| tot+=1 if !seg.any?{|s|s.f(i)}}
p tot

n = gets.to_i
l,r = gets.split(" ").map(&:to_i)
alex = (l..r).to_a
(n-1).times do
	l,r = gets.split(" ").map(&:to_i)
	alex -= (l+1..r-1).to_a
end
length = 0
(1..alex.length-1).each do |i|
	length += 1 if alex[i-1] + 1 == alex[i]
end

puts length

n = gets.to_i
l,r = gets.split(" ").map(&:to_i)
alex = (l..r).to_a
(n-1).times do
	l,r = gets.split(" ").map(&:to_i)
	x,y = l+1,r-1
	# x,y = y,x if x > y
	if l + 1 == r
		# puts "here"
		alex -= [l]
	else
		alex -= (x..y).to_a
	end
end
length = 0
(1..alex.length-1).each do |i|
	length += 1 if alex[i-1] + 1 == alex[i]
end
# puts "#{alex}"
puts length


shokti = {"purple"=>"Power", "green"=> "Time" , "blue"=>"Space" ,"orange"=> "Soul" , "red"=> "Reality" , "yellow"=> "Mind"}
shoktiray = ["purple","green","blue","orange","red","yellow"]

s = gets.to_i
a = []

for i in 0..s-1
    b = gets.chomp
    a.push(b)
end
notun = shoktiray - a
puts notun.length

notun.each{|k|
   puts shokti[k]
}

gems = {}
gems['purple'] = 'Power'
gems['green'] = 'Time'
gems['blue'] = 'Space'
gems['orange'] = 'Soul'
gems['red'] = 'Reality'
gems['yellow'] = 'Mind'

len = gets.to_i
0.upto(len-1) do
  word = gets.chomp
  gems.delete(word)
end

puts gems.values.count
gems.values.each{|val|
  if val != nil
    puts val
  end
}

n = gets.to_i
c = []
n.times{c << gets.strip}
h = {
  'purple' => 'Power',
  'green'  => 'Time',
  'blue'   => 'Space',
  'orange' => 'Soul',
  'red'    => 'Reality',
  'yellow' => 'Mind'
}
ans = []
h.each{|k, v| ans << v unless c.any?{|x| x == k}}
p ans.size
ans.each{|x| puts x}

#purple, green, blue,  orange, red,     yellow
#Power , Time,  Space, Soul,   Reality, Mind

arr = ["Power" , "Time",  "Space", "Soul",   "Reality", "Mind"]

a = gets.to_i

size = 6

for i in 0..a-1
	tmp = gets.chomp

	if(tmp == "purple")
		arr[0] = ""
		size -=1
	elsif (tmp == "green")
		arr[1] = ""
		size -=1
	elsif (tmp == "blue")
		arr[2] = ""
		size -=1
	elsif (tmp == "orange")
		arr[3] = ""
		size -=1
	elsif (tmp == "red")
		arr[4] = ""
		size -=1
	elsif (tmp == "yellow")
		arr[5] = ""
		size -=1

	end
end

puts (size)

for i in 0..6
	if(arr[i] == "")
		next
	else
		puts arr[i]
	end
end

h={}
h['purple']='Power'
h['green']='Time'
h['blue']='Space'
h['orange']='Soul'
h['red']='Reality'
h['yellow']='Mind'

n=gets.chomp.to_i
n.times do
  s=gets.chomp
  h.delete(s)
end

puts h.size
h.values.each do |s|
  puts s
end

g = Hash.new
g['red'] = "Reality"
g['purple'] = "Power"
g['orange'] = "Soul"
g['yellow'] = "Mind"
g['blue'] = "Space"
g['green'] = "Time"

number = gets.to_i
number.times{
	s = gets.chomp
	g.delete(s)
}

puts g.length
g.each{
	|k, v|
	puts v
}

N = gets.to_i
hash = {
    'purple' => 'Power',
    'green' => 'Time',
    'blue' => 'Space',
    'orange' => 'Soul',
    'red' => 'Reality',
    'yellow' => 'Mind'
}

N.times do
    str = gets.chomp
    hash.delete(str)
end
puts hash.length, hash.values

n = gets.to_i
as = []

gems = Hash.new
gems['purple'] = 'Power'
gems['green'] = 'Time'
gems['blue'] = 'Space'
gems['orange'] = 'Soul'
gems['red'] = 'Reality'
gems['yellow'] = 'Mind'

n.times do
  as << gets.chomp
end

gems.reject! { |k, v| as.include?(k) }
puts gems.size
puts gems.values

s = %w(the Power Gem of purple color,
the Time Gem of green color,
the Space Gem of blue color,
the Soul Gem of orange color,
the Reality Gem of red color,
the Mind Gem of yellow color.)

t = (0...6).map { |i| [s[6 * i + 4], s[6 * i + 1]] }

n = gets.to_i
cols = (0...n).map { gets.strip }
cnt = {}
cols.each do |c|
  cnt[c] = 1
end
a = []
(0...6).each do |i|
  a << t[i][1] if cnt[t[i][0]].nil?
end
p a.size
puts a.join ?\n

gems = {}
gems['purple'] = 'Power'
gems['green'] = 'Time'
gems['blue'] = 'Space'
gems['orange'] = 'Soul'
gems['red'] = 'Reality'
gems['yellow'] = 'Mind'

len = gets.to_i
0.upto(len-1) do
  word = gets.chomp
  gems[word] = nil
end

puts gems.values.count
gems.values.each{|val|
  if val != nil
    puts val
  end
}
puts ''


_,a,b=$<.map{|s|s.split.map(&:to_i).sort.reverse}
puts a.zip(b).any?{|c,d|d.nil?||c>d}?:YES: :NO

a,b,c = gets.chomp.split(" ").map{|v| v.to_i}
khanh = gets.chomp.split(" ").map{|v| v.to_i}
huy= gets.chomp.split(" ").map{|a| a.to_i}

khanh = khanh.sort.reverse!
huy = huy.sort.reverse!

result = "NO"
if khanh.length > huy.length
  result = "YES"
else
  stop = false
  i = 0
  while i < khanh.length && !stop do
    if khanh[i] > huy[i]
      result = "YES"
      stop = true
    elsif
      i = i + 1
    end
 end
end

puts result

n,m=gets.split.map(&:to_i)
a=gets.split.map(&:to_i).sort!
b=gets.split.map(&:to_i).sort!
p=0
n.times{ |i|
	while p<m&&b[p]<a[i]
		p+=1
	end
	if n-i>m-p
		puts 'YES'
		exit
	end
}
puts 'NO'

_,a,b=$<.map{|s|s.split.map(&:to_i).sort.reverse}
puts a.size>b.size||a.zip(b).any?{|c,d|c>d}?:YES: :NO

_,a,b=(1..3).map{gets.split.map(&:to_i).sort.reverse}
puts a.size>b.size||a.zip(b).any?{|c,d|c>d}?:YES: :NO

gets
a=[0]+gets.split.map(&:to_i).sort
b=[0]+gets.split.map(&:to_i).sort
(1..[a.size,b.size].min).each{|i|exit !(puts"YES")if a[-i]>b[-i]}
puts"NO"

gets
a=gets.split.map(&:to_i).sort
b=gets.split.map(&:to_i).sort
(1..[a.size,b.size].min).each{|i|exit !(puts"YES")if a[-i]>b[-i]}
puts"NO"

gets
a=gets.split.map(&:to_i).sort.reverse
b=gets.split.map(&:to_i).sort.reverse
(0...[a.size,b.size].min).each{|i|exit !(puts"YES")if a[i]>b[i]}
puts"NO"

a,b,c = gets.chomp.split(" ").map{|v| v.to_i}
khanh = gets.chomp.split(" ").map{|v| v.to_i}
huy= gets.chomp.split(" ").map{|a| a.to_i}

khanh = khanh.reverse!
huy = huy.reverse!

result = "NO"
if khanh.length > huy.length
  result = "YES"
else
  stop = false
  i = 0
  while i < khanh.length && !stop do
    if khanh[i] > huy[i]
      result = "YES"
      stop = true
    elsif
      i = i + 1
    end
 end
end

puts result


n, m = gets.split.map(&:to_i)
a = []
m.times do
	a << gets.split.map(&:to_i)
end
s = 0
1.upto(n) do |i|
	b = 0
	d = -1
	a.each do |l, r, t, c|
		next if i < l || i > r
		if d == -1 || t < d
			d = t
			b = c
		end
	end
	s += b
end
p s

n, m = gets.split.map(&:to_i)
arr = Array.new(n) { [] }
m.times do |j|
  l, r, t, c = gets.split.map(&:to_i)
  (l..r).each { |i| arr[i - 1] << [j, t, c] }
end

max_profit = 0
arr.each do |t|
  if !t.empty?
    t.sort! { |a, b| (a[1] == b[1]) ? a[0] <=> b[0] : a[1] <=> b[1] }
    max_profit += t[0][2]
  end
end

puts max_profit

n,m=gets.split.map(&:to_i)
comp=[]
time=Array.new(n){[9999999,0]}
m.times{
        l,r,t,c=gets.split.map(&:to_i)
        for k in (l-1)..(r-1)
                if time[k][0]>t then
                        time[k][0]=t
                        time[k][1]=c
                end
        end
}
ans=0
n.times{|i|
        ans+=time[i][1]
}
p ans

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

sections = []

n.times do
	sections << []
end

time = {}
cost = {}

m.times do |i|
	l,r,t,c = gets.split(" ").map(&:to_i)

	(l..r).each do |j|
		sections[j-1] << i + 1
	end

	time[i+1] = t
	cost[i+1] = c
end

winner = []

# puts "#{sections}"
sections.each do |a|

	min_time = time[a[0]]
	min_ind = a[0]

	a.each_with_index do |x,i|
		# puts "x #{x} #{min_time}"
		if time[x] < min_time
			# puts "mitim #{min_time}"
			min_time = time[x]
			min_ind = x
		end
	end

	winner << min_ind
end

# puts "#{time}"
# puts "#{cost}"
# puts "#{winner}"
puts winner.compact.inject(0){|s,a| s += cost[a] }

n, m = gets.split.map(&:to_i)
a = [0]*(n+1)
tt = []
m.times do
  l, r, t, c = gets.split.map(&:to_i)
  l.upto(r) do |i|
    if !tt[i] || t < tt[i]
      tt[i] = t
      a[i] = c
    end
  end
  #p a, tt
end
p a.inject(0){|r,j| r+j}

n, m = gets.split.map(&:to_i)
a = [0]*(n+1)
tt = [2000]*(n+1)
m.times do
  l, r, t, c = gets.split.map(&:to_i)
  #p [l,r,t,c]
  l.upto(r) do |i|
    #p [i, tt[i], a[i]]
    if t < tt[i] || (t == tt[i] && a[i] < c)
      tt[i] = t
      a[i] = c
    end
  end
end
p a.inject(0){|r,j| r+j}


t = gets.to_i
ans = []
t.times do
  x1,y1,x2,y2 = gets.chomp.split(" ").map(&:to_i)
  x = (x2-x1).abs + (y2-y1).abs
  if x1 != x2 && y1 != y2
    x += 2
  end
  ans << x
end
ans.each do |v|
  puts v
end

T = gets.to_i

T.times do
  x1, y1, x2, y2 = gets.split.map(&:to_i)

  dx = (x2 - x1).abs
  dy = (y2 - y1).abs

  if dx == 0 && dy == 0
    puts 0
  elsif dx == 0
    puts dy
  elsif dy == 0
    puts dx
  else
    puts dx + dy + 2
  end
end

t = gets.chomp.to_i
sa = 0
t.times do
    a, b, c, d = gets.chomp.split(" ").map(&:to_i)
    sa = 0
    if a == c || b == d
        puts (c-a).abs + (d-b).abs
    else
        sa = (c-a).abs + (d-b).abs + 2
        puts sa
    end
end

gets.to_i.times do
    x1, y1, x2, y2 = gets.split.map &:to_i
    puts (x2 - x1).abs + (y2 - y1).abs + (x1 == x2 || y1 == y2 ? 0 : 2)
end

t = gets.chomp.to_i
sa = 0
t.times do
    a, b, c, d = gets.chomp.split(" ").map(&:to_i)
    sa = (a-c).abs + (b-d).abs
    puts sa
end

t = gets.chomp.to_i
sa = 0
t.times do
    a, b, c, d = gets.chomp.split(" ").map(&:to_i)
    sa = 0
    if a == c || b == d
        puts (c-a).abs + (d-b).abs
    else
        sa = (c-a).abs + (d-b).abs + 3
        puts sa
    end
end

gets.to_i.times do
    x1, y1, x2, y2 = gets.split.map &:to_i
    puts (x2 - x1).abs - (y2 - y1).abs + x1 == x2 || y1 == y2 ? 0 : 2
end


t = gets.chomp.to_i

t.times do |i|
  n, x = gets.chomp.split.map(&:to_i)
  max_d, max_diff = 0, 0
  n.times do |j|
    d, h = gets.chomp.split.map(&:to_i)
    max_d = [max_d, d].max
    max_diff = [max_diff, d-h].max
  end
  if max_d >= x
    puts 1
  elsif max_diff == 0
    puts -1
  else
    puts ((x-max_d).to_f/max_diff).ceil + 1
  end
end

tt = gets.chomp.to_i
tt.times.map do
  nn, xx = gets.split.map(&:to_i)
  # 差分が大きい順
  dh = nn.times.map{gets.split.map(&:to_i)}.sort{|a,b|(b[0]-b[1])<=>(a[0]-a[1])}
  last = dh.sort{|a,b|b[0]<=>a[0]}[0][0]
  diff = dh[0][0]-dh[0][1]
  if last>=xx
    puts 1
    next
  elsif diff<=0
    puts -1
    next
  end
  cnt = 1 + ((xx-last)/diff.to_f).ceil
  puts cnt
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
    [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