def main @T = int @T.times do res1 = ints res2 = ints x = STATUSES.index string yesno (res2.each_with_index.all? { |c, i| i == 0 or i == x or c == 0 } and res1[0] >= res2[0] and res1[x] == 0 and res2[x] == res1.sum - res2[0]) end end STATUSES = %w(AC WA TLE MLE OLE RE) DEBUG = false 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 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< 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 wa - ac > 1; if yield(wj = (ac + wa) / 2); ac = wj else wa = wj end; end; yield(ac) ? ac : nil 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..]) 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 widest(&block); Enumerator.new { |y| i, n = 0, size; j = upper_bound { |j| block[i, j] } || next; y.yield(i, j); (i...n).each { |i| j += 1 while j + 1 < n and block[j + 1]; y.yield(i, j) } } end def cum(id=nil, &op); a = []; x = id ? (a << op[id, self[0]]; x[0]) : self[0]; (1...size).each { |i| x = op[x, a[i]]; a << x }; a end end class Iterator def initialize(enum); @f = Fiber.new { enum.each { |x| Fiber.yield x }; break } end def next; @f.resume rescue @f = nil if @f end def finish?; @f.nil?; end def to_a; each.to_a; end def each; return Enumerator.new { |y| drain { |x| y << x } } unless block_given?; yield self.next rescue break while true 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 #def cumdiff; xs = []; inject { |x, y| xs << (d = y - x); d } end #def cum(id, &op); ys = [id]; each { |x| ys << op[x, ys[-1]] }; ys end end class UnionFind def initialize(size); @p, @r = size.times.to_a, [1] * size end def merge(i, j); k, l = leader(i), leader(j); return if k == l; k, l = l, k if @r[k] < @r[l]; @p[l] = k; @r[k] += @r[l]; end def size(i); @r[leader(i)] end def same?(i, j); leader(i) == leader(j) end def leader(i); j = i; j, i = i, @p[j] = @p[i] until i == @p[i]; i end end class Factorials def initialize(limit, mod = MOD); @fac, @fin, @inv, @mod = [1, 1], [1, 1], [nil, 1], mod; (2..limit).each { |i| @fac[i] = @fac[i-1] * i % mod; @inv[i] = mod - @inv[mod % i] * (mod / i) % mod; @fin[i] = @fin[i-1] * @inv[i] % mod }; end def fact(n); @fac[n]; end def comb(n, k); perm(n, k) * @fin[k] % @mod; end def perm(n, k); @fac[n] * @fin[n-k] % @mod; end end main