Nick is building a new web server, and the feature he is working on now is support for access control lists. An access control list restricts access to some resources on a web site based on the IP address of the requesting party.
Each IP address is a 4-byte number written byte by byte in decimal dot-separated notation byte0.byte1.byte2.byte3. Each byte is a decimal number from 0 to 255 (inclusive) written without extra leading zeroes. IP addresses are organized into IP networks.
An IP network is described by two 4-byte numbers: a network address and a network mask, both written in the same notation as IP addresses.
To understand the meaning of the network address and network mask, consider their binary representation. The binary representation of an IP address, network address, or network mask consists of 32 bits: 8 bits for byte0 (most significant to least significant), then 8 bits for byte1, then 8 bits for byte2, then 8 bits for byte3.
An IP network contains a range of 2^n IP addresses, where 0 <= n <= 32. The network mask always has its first 32 - n bits set to one and its last n bits set to zero. The network address has arbitrary first 32 - n bits and its last n bits set to zero. The IP network contains every IP address whose first 32 - n bits equal the first 32 - n bits of the network address, with the last n bits arbitrary.
For example, the IP network with network address 194.85.160.176 and network mask 255.255.255.248 contains 8 IP addresses from 194.85.160.176 to 194.85.160.183 (inclusive).
IP networks are usually written as byte0.byte1.byte2.byte3/s, where byte0.byte1.byte2.byte3 is the network address and s is the number of bits set to one in the network mask. For example, the network above is written as 194.85.160.176/29.
An access control list contains an ordered list of rules. Each rule has one of the following forms:
deny from <IP network> — deny access to any IP address in the given IP network.deny from <IP address> — deny access to the given IP address.allow from <IP network> — allow access to any IP address in the given IP network.allow from <IP address> — allow access to the given IP address.When a party requests a resource, its IP address is checked against the access control list. The rules are scanned in the order they are listed, and the first matching rule is applied. If no rule matches the IP address, access is granted.
Given an access control list and a list of requesting IP addresses, determine for each request whether access to the resource is granted.
The first line contains n — the number of rules in the access control list (0 <= n <= 100000). The next n lines each contain one rule. An IP network is always written as byte0.byte1.byte2.byte3/s.
The next line contains m — the number of IP addresses to check (1 <= m <= 100000). The following m lines each contain one IP address to check.
For each request output A if access is granted, or D if access is denied. Output all answers on one line, with no spaces separating them.