This page is still under construction.

Parts of this page are still being built. What you see may change.

Movie Theater Seating

Time limit2sMemory limit64 MB

Summary
Decide whether S solo guests and C couples fit into R rows of 8 seats with reserved seats while keeping neighbors and front seats empty.
Level

Medium7 of 10

Topics
Dynamic programming, Bit manipulation, Backtracking
Solved
No attempts yet

Problem

Haebin runs a movie theater with RR rows of 8 seats each. Some seats are already reserved, and three kinds of guests walk in.

  • guests who reserved a seat
  • solo guests who did not reserve
  • couples who did not reserve (a couple wants to sit side by side)

A guest who reserved simply takes the reserved seat. Haebin has to seat the remaining SS solo guests and CC couples under these rules.

  • A solo guest only takes a seat that is not reserved.
  • A solo guest hates having anyone beside them in the same row.
  • A solo guest hates having anyone in the seat directly in front of them.
  • A couple takes two adjacent seats in the same row, and neither seat is reserved.
  • Other than the partner, a couple hates having anyone beside them in the same row.
  • A couple hates having anyone in the seats directly in front of them.

The seat directly in front of a given seat is the seat in the same column of the row immediately ahead. The word anyone in these rules covers reserved guests, solo guests and couples alike. Reserved guests are easygoing and ignore every rule above.

Given the reserved seats, the number of solo guests SS and the number of couples CC, decide whether the solo guests and the couples can all be seated under the rules.

Input

The first line contains the number of test cases TT (T≤20T \le 20).

The first line of each test case contains three integers RR, SS and CC (1≤R≤201 \le R \le 20, 0≤S≤300 \le S \le 30, 0≤C≤300 \le C \le 30). The next RR lines correspond to the seat rows from the front row of the theater to the back row. Each line is a binary string of length 8, where 0 is a seat that is not reserved and 1 is a reserved seat.

Output

For each test case, print YES on its own line if everyone can be seated under the rules, and NO otherwise.

Examples1

  1. Example 1

    Input
    3
    3 5 1
    00000000
    01111100
    00000000
    2 4 1
    00000000
    10011000
    2 5 1
    00000000
    10011000
    
    Expected output
    YES
    YES
    NO