В IDEA все выводит как надо
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 {
// List of addresses
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
HashMap<String, String> people = new HashMap<>();
while (true) {
String familyName = reader.readLine();
if ((familyName==null) || familyName.isEmpty())
{break;}
String city = reader.readLine();
if ((city==null) || city.isEmpty()) {
break; }
people.put(familyName, city);
}
for (Map.Entry<String,String> whatElse : people.entrySet()){
String key = whatElse.getKey();
String value = whatElse.getValue();
String entry = reader.readLine();
if ((entry==null) || entry.isEmpty()){
break;}
if (entry.equals(value)){
System.out.println(key);
break;
}
}
}
}