Routing
To determine the routes for network packets in modern networks, special devices known as routers are employed. These routers rely on a routing table to guide their operations. A routing table consists of rows that describe routes, with each row containing three fields: D, M, and G. Here, D represents the destination network's IP address, M is the mask, and G is the gateway's IP address (note that real tables have additional fields). For instance, the row 192.168.24.0 255.255.255.0 192.168.14.1 indicates that a packet destined for the network 192.168.24.0 with the mask 255.255.255.0 should be routed through the gateway 192.168.14.1.
Brief Reference. An IP address is a 32-bit number. For ease of use, it is expressed in dotted-decimal format, where each byte is shown in decimal form, separated by dots. For example, the notation 192.168.24.0 corresponds to the binary number 11000000101010000001100000000000. The same format applies to masks. Masks have a distinctive feature: in their binary form, they always begin with ones followed by zeros. The gateway address cannot be composed entirely of zero or one bits.
The route selection algorithm operates as follows. Suppose a packet is addressed to address A. The router first examines all entries and retains only those where the condition D and M = A and M (and is the bitwise "AND" operation) holds true. From these entries, the one with the maximum number of one bits in the mask is chosen as the result. It is guaranteed that for any address, there will be no more than one such entry.
The larger the table size, the slower the router functions and the more resources it consumes. However, in many instances, the given table can be transformed into an equivalent one with fewer rows.
For example, consider the first table:
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
And the second table:
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 straightforward to verify that for any destination address, the same gateway will be determined by these two tables (or none will be determined). Note that in this task, the destination address can be any 32-bit number (i.e., there are no special or invalid addresses as in real networks).
Manually comparing large tables can be quite tedious. Your task is to write a program to check the equivalence of two given tables.
Input
The first line of the input file contains an integer N (from 1 to 100,000) — the number of entries in the first routing table. The following N lines contain the routing table in the specified format. Then an integer M (from 1 to 100,000) is provided — the number of entries in the second table. The next M lines contain the second routing table.
Output
On the first line of the output file, print either YES or NO.