package com.javarush.task.task08.task0829;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/*
Модернизация ПО
*/

public class Solution {
    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
// List of city
        Map<String, String> map = new HashMap<>();
        while (true) {
            if (reader.readLine().isEmpty()) break;

                String city = reader.readLine();     // sozdal Map i dobavil gorod i Familiyu

                String family = reader.readLine();


                map.put(city, family);

        }
            String checkCity = reader.readLine();
            for (Map.Entry<String, String> entry : map.entrySet()) {
                if (checkCity.equals(entry.getKey())) {                                  // proverka estli
                                                                                                          // vvedenniy gorod sovpodaet s gorodom
                                                                                                          // iz spiska vivoju familiyu
                    System.out.println(entry.getValue());
                }
            }
        }
    }