import java.util.*; public class Main { static long off(String s, long total){ if (s.charAt(s.length()-1) == '1') return total/2; return total*3/10; } static class ob { String cv, x, code, name; Long hs; public ob(String code, String name){ cv = code.substring(0,2); x = code.substring(2,4); this.code = code.substring(4); this.name = name; hs = Long.parseLong(x); } public String toString() { return name + " " + cv + " " + code + " " + x; } } public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); ArrayList a = new ArrayList<>(); sc.nextLine(); int gd=0, tp=0, pp=0; for(int i=0;i { if(x.hs == y.hs) return x.code.compareTo(y.code); return y.hs.compareTo(x.hs); }); int q = sc.nextInt(); while(q-->0){ String code = sc.next(); a.forEach(e -> { if(e.cv.compareTo(code) == 0) System.out.println(e); }); System.out.println(); } } }