Problem

7 /9


File system

Problem

The file system of one supercomputer was infiltrated by a virus that broke file access control. For each Ni file, it is known what actions can be accessed with it:
 
record W
read R
launching X
 
You need to regain control over file permissions (your program will need to return OK for each request if a valid operation is being performed on the file, or Access denied if the operation is invalid).
 
Input
The first line contains a number N (1 <= N <= 10000) - number of files contained in this file system.
The following N lines contain the names of files and the operations allowed with them, separated by spaces. The file name is limited to 15 characters.
The following is the number M (1 <= M <= 50000) - number of file requests.
The last M lines contain a query like Operation File. Any number of queries can be applied to the same file.
 
Output
For each of the M requests, print Access denied or OK.
on a separate line  
 
Example
# Input Output
1
4
helloworld.exe R X
pinglog W R
nya R
goodluck X W R
5
read nya
write helloworld.exe
execute nya
read ping log
write pinglog
OK
Access denied
Access denied
OK
OK