/*坑点:人数可能为0!!!*/
#include<iostream>
#include<string>
#include <vector>
#include <algorithm>
#include <vector>
using namespace std;
int N, M;
int gold, jp, people;
struct nation {
    int id;
    double gold_num;//金牌数
    double jp_num;//奖牌数
    double gpldbl;//金牌比例
    double jpbl;//奖牌比例
    int way;//最优的排名方法
    int mingci;//最优排名方式下的排名
};
nation n;
int main() {
    while (cin >> N >> M && (N >= M)) {
        vector<nation> old_gj;
        vector<nation> gj;
        for (int i = 0; i < N; i++) {
            cin >> gold >> jp >> people;
            n.gold_num = gold;
            n.jp_num = jp;
            if (people == 0) {
                if (gold == 0) n.gpldbl = 0;
                else n.gpldbl = (double)gold / (double)people;
                if (jp == 0) n.jpbl = 0;
                else n.jpbl = (double)jp / (double)people;
            } else {
                n.gpldbl = (double)gold / (double)people;
                n.jpbl = (double)jp / (double)people;
            }
            n.id = i;
            old_gj.push_back(n);
        }
        int id;
        for (int i = 0; i < M; i++) {
            cin >> id;
            gj.push_back(old_gj[id]);
        }
        //将每种排序方式都进行排序
        vector<nation> way1 = gj;
        vector<nation> way2 = gj;
        vector<nation> way3 = gj;
        vector<nation> way4 = gj;
        sort(way1.begin(), way1.end(), [](const nation & a, const nation & b) {
            return a.gold_num > b.gold_num;
        });
        sort(way2.begin(), way2.end(), [](const nation & a, const nation & b) {
            return a.jp_num > b.jp_num;
        });
        sort(way3.begin(), way3.end(), [](const nation & a, const nation & b) {
            return a.gpldbl > b.gpldbl;
        });
        sort(way4.begin(), way4.end(), [](const nation & a, const nation & b) {
            return a.jpbl > b.jpbl;
        });
        int index = 0;
        for (auto it = gj.begin(); it != gj.end(); it++) {
            int i = (*it).id;
            int min_way;
            int min_no = M + 1;
            bool flag1 = 0, flag2 = 0, flag3 = 0, flag4 = 0;
            for (int k = 0; k < M; k++) {
                if (way1[k].id == i) {
                    int j = k;
                    flag1 = 1;
                    while (j > 0 && way1[j].gold_num == way1[j - 1].gold_num) {
                        j--;
                    }
                    if (min_no > j + 1 || (min_no == j + 1 && min_way > 1)) {
                        min_no = j + 1;
                        min_way = 1;
                    }
                }
                if (way2[k].id == i) {
                    int j = k;
                    flag2 = 1;
                    while (j > 0 && way2[j].jp_num == way2[j - 1].jp_num) {
                        j--;
                    }
                    if (min_no > j + 1 || (min_no == j + 1 && min_way > 2)) {
                        min_no = j + 1;
                        min_way = 2;
                    }
                }
                if (way3[k].id == i) {
                    int j = k;
                    flag3 = 1;
                    while (j > 0 && way3[j].gpldbl == way3[j - 1].gpldbl) {
                        j--;
                    }
                    if (min_no > j + 1 || (min_no == j + 1 && min_way > 3)) {
                        min_no = j + 1;
                        min_way = 3;
                    }
                }
                if (way4[k].id == i) {
                    int j = k;
                    flag4 = 1;
                    while (j > 0 && way4[j].jpbl == way4[j - 1].jpbl) {
                        j--;
                    }
                    if (min_no > j + 1) {
                        min_no = j + 1;
                        min_way = 4;
                    }
                }
                if (flag1 && flag2 && flag3 && flag4) {
                    gj[index].mingci = min_no;
                    gj[index].way = min_way;
                    break;
                }
            }
            gj[index].mingci = min_no;
            gj[index].way = min_way;
            index++;
        }
        for (int i = 0; i < M; i++) {
            cout << gj[i].mingci << ":" << gj[i].way << endl;
        }
        cout << endl; //每组数据后加一个空行。
    }
}
// 64 位输出请用 printf("%lld")