/* * Sample solution to Boss in java/ Mikael Goldmann * * Your immediate boss is the person who... * earns the least... * ...among those at least as tall and earn strictly more * Salaries are unique * Also compute subordinates */ import java.util.*; import java.io.*; class Emp implements Comparable { public int ID, sal, hte, boss, nsub; public Emp() { nsub = 0; } public int compareTo(Object o) { // all salaries distinct return sal - ((Emp)o).sal; } } class boss_mg { static BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in)); static StreamTokenizer tokens = new StreamTokenizer(stdin); static BufferedWriter stdout = new BufferedWriter(new OutputStreamWriter(System.out)); static int getInt() throws IOException { tokens.nextToken(); return (int)Math.round(tokens.nval); } public static void main(String[] as) throws IOException { int n = getInt(); for (int i = 0; i < n; ++i) solve(); stdout.close(); } static void solve() throws IOException { int nemp = getInt(); int nq = getInt(); int[] IDtoIndex = new int[1000000]; Emp[] emp = new Emp[nemp]; for (int i = 0; i < nemp; ++i) { emp[i] = new Emp(); emp[i].ID = getInt(); emp[i].sal = getInt(); emp[i].hte = getInt(); emp[i].boss = -1; } Arrays.sort(emp); for (int i = 0; i < nemp; ++i) IDtoIndex[emp[i].ID] = i; for (int i = nemp-2; i >= 0; --i) { int b = i+1; while(emp[i].hte > emp[b].hte) b = emp[b].boss; emp[i].boss = b; } for (int i = 0; i < nemp-1; ++i) emp[emp[i].boss].nsub += (1 + emp[i].nsub); for (int i = 0; i < nq; ++i) { int q=0; String s=""; q = getInt(); int ix = IDtoIndex[q]; int bix = emp[ix].boss; if (bix == -1) s = "0"; else s = "" + emp[bix].ID; s += " " + emp[ix].nsub; stdout.write(s, 0, s.length()); stdout.newLine(); } stdout.flush(); } }