// Stephen Fulwider
//	Military Roster - First Week Programming Contest for BHCSI 2010

// This program uses a TreeMap to store a map from Strings -> Strings
//	to store all the current IDs and the name associated with them
// It then uses the .containsKey() method to find out if an ID is 
//	already mapped

import java.util.Scanner;
import java.util.TreeMap;


public class roster
{

	public static void main(String[] args)
	{
		new roster();
	}
	
	roster()
	{
		Scanner in=new Scanner(System.in);
		int N=in.nextInt();
		
		// this is our map storing ID -> name
		TreeMap<String,String> M=new TreeMap<String,String>();
		
		// read in the current roster
		for (int i=0; i<N; ++i)
			M.put(in.next(), in.next());
		
		int Q=in.nextInt();
		
		// read in each query and check if in map
		for (int i=0; i<Q; ++i)
		{
			String id=in.next();
			if (M.containsKey(id))
				System.out.println(id+" is in the books as "+M.get(id));
			else
				System.out.println(id+" is an available ID");
		}
	}

}
