import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); ArrayList allList = new ArrayList<>(); HashSet outSet = new HashSet<>(); for (int i = 0; i < n; i++) { String a = sc.next(); String b = sc.next(); allList.add(b); outSet.add(a); } StringBuilder sb = new StringBuilder(); HashSet putSet = new HashSet<>(); for (String s : allList) { if (!outSet.contains(s) && !putSet.contains(s)) { sb.append(s).append("\n"); putSet.add(s); } } System.out.print(sb); } }