To determine the routes for network packets in modern networks, special devices called routers are used. Routers rely on a routing table to operate. A routing table consists of rows describing routes, where each row contains 3 fields: , , and . Here, is the destination network's IP address, is the mask, and is the gateway's IP address (note: real tables may have more fields). For example, the row 192.168.24.0 255.255.255.0 192.168.14.1 states that a packet addressed to the network 192.168.24.0 with the mask 255.255.255.0 should be sent through the gateway 192.168.14.1.
Brief Reference. An IP address is a -bit number. For convenience, it is written in dotted-decimal format: each byte in decimal, separated by dots. For example, 192.168.24.0 stands for the binary number 11000000101010000001100000000000. The same applies for masks. Masks have the key property that their binary representation contains only ones followed by only zeros. The gateway address cannot consist entirely of zero or one bits.
The route selection algorithm works as follows. Suppose a packet is addressed to address . The router reviews all entries and keeps only those for which the condition D \land M = A \land M ( is the bitwise "AND" operation) holds. From these, the entry with the largest number of ones in the mask is selected — this will be the result. It is guaranteed that for any address, there is at most one such entry.
The larger the table, the slower the router and the more resources it consumes. However, in many cases, the given table can be transformed into an equivalent one with fewer rows.
For example, the first table may look like this:
192.168.0.0 255.255.255.0 192.168.14.1
192.168.1.0 255.255.255.0 192.168.14.1
192.168.2.0 255.255.255.0 192.168.14.2
192.168.3.0 255.255.255.0 192.168.14.2
The second table may look like this:
192.168.0.0 255.255.252.0 192.168.14.1
192.168.2.0 255.255.254.0 192.168.14.2
It is easy to see that for any destination address, the same gateway will be determined for both tables (or none will be determined). Note that in this problem, the destination address can be any -bit number (i.e., there are no special or invalid addresses as in real networks).
Comparing large tables by hand is tedious. Your task is to write a program to check the equivalence of two given tables.
The first line of the input file contains an integer (from to ) — the number of entries in the first routing table. The following lines contain the routing table in the described format. Then an integer (from to ) is given — the number of entries in the second table. The next lines contain the second routing table.
On the first line of the output file, print either YES or NO.
Example 1