Server Configuration

View as PDF

Submit solution

Points: 50.00
Time limit: 1.0s
Memory limit: 256M
Input: stdin
Output: stdout

Author:
Suggester:
Problem type

Students in the Cyber Warfare class are required to configure web servers while studying Computer Network Administration. Teachers are required to add server name comments after each configuration command. However, during the configuration process, the students forgot to add these comment lines.

The class is required to configure n servers, each server is represented by a name and an ip address (name - the server names can be the same, but the ip addresses of the servers are unique). For simplicity, let's assume that the web server configuration command is of the form 'commnand ip;' where command is a string consisting of only lowercase English letters and ip is the ip address of one of the servers that needs to be configured. Each ip address has the form 'A.B.C.D' where A, B, C and D (0 ≤ A, B, C, D ≤ 255).

The web server configuration file is required to include a comment line of the form 'command ip; #name'. None of the students remembered the server's ip, so adding comment lines to the commands was very complicated.

Please write a program to help students add comment lines to configuration commands to meet the teacher's requirements.

Input:

  • The first line contains two positive integers n and m (1 ≤ n, m ≤ ~10^3~), n is the server number and m is the number of configuration commands in the configuration file.
  • The next n lines contain the name and ip of the server. Each line contains a string name (hostname) and an ip string (server ip address), separated by a space (1 ≤ |name| ≤ 10, name consists of English lowercase letters only). All ip addresses are unique.
  • The next m lines contain commands in the configuration file. Each line has the form 'command ip;' (1 ≤ |command| ≤ 10, command includes only lowercase English letters). The ip addresses must belong to one of the ip addresses of the n given hosts.

Output: Include m command lines in the configuration file after performing the task of adding comments.

Example

Input 1

2 2
main 192.168.0.2
replica 192.168.0.1
block 192.168.0.1
proxy 192.168.0.2

Output 1

block 192.168.0.1; #replica
proxy 192.168.0.2; #main

Input 2

3 5
google 8.8.8.8
education 212.193.33.27
server 138.197.64.57
redirect 138.197.64.57
block 8.8.8.8
cf 212.193.33.27
unblock 8.8.8.8
check 138.197.64.57

Output 2

redirect 138.197.64.57; #server
block 8.8.8.8; #google
cf 212.193.33.27; # education
unblock 8.8.8.8; #google
check 138.197.64.57; #server

Comments

Please read the guidelines before commenting.


There are no comments at the moment.