#include<iostream>
#include<algorithm>
using namespace std;
struct country {
int jin, jiang, num, pai; //金牌,奖牌,序号
float jp, jiap; //金牌人口比,奖牌人口比
} a[1000];
struct pos {
int num;
int s1, s2, s3, s4; //四种排名
} b[1000];
bool cmp1(country c1, country c2) {
return c1.jin > c2.jin;
}
bool cmp2(country c1, country c2) {
return c1.jiang > c2.jiang;
}
bool cmp3(country c1, country c2) {
return c1.jp > c2.jp;
}
bool cmp4(country c1, country c2) {
return c1.jiap > c2.jiap;
}
int main() {
int n, m;
while (scanf("%d%d", &n, &m) != EOF) {
int temp;
for (int i = 0; i < n; i++) {
cin >> a[i].jin >> a[i].jiang >> temp;
a[i].jp = (float)a[i].jin / temp;
a[i].jiap = (float)a[i].jiang / temp;
a[i].num = i;
}
for (int i = 0; i < m; i++) {
cin >> b[i].num;
}
sort(a, a + n, cmp1); //按金牌排序
for (int i = 0; i < n; i++) { //1.解决1,2,2,4情况
if (i > 0 && a[i].jin == a[i - 1].jin) {
a[i].pai = a[i - 1].pai;
} else a[i].pai = i + 1;
}
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
if (b[i].num == a[j].num)b[i].s1 =
a[j].pai; // 2,解决根据编号查排名情况。
}
}
sort(a, a + n, cmp2); //按奖牌排序
for (int i = 0; i < n; i++) {
if (i > 0 && a[i].jiang == a[i - 1].jiang) {
a[i].pai = a[i - 1].pai;
} else a[i].pai = i + 1;
}
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
if (b[i].num == a[j].num)b[i].s2 =
a[j].pai; // 2,解决根据编号查排名情况。
}
}
sort(a, a + n, cmp3); //按金牌人口比例排序
for (int i = 0; i < n; i++) {
if (i > 0 && a[i].jp == a[i - 1].jp) {
a[i].pai = a[i - 1].pai;
} else a[i].pai = i + 1;
}
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
if (b[i].num == a[j].num)b[i].s3 =
a[j].pai; // 2,解决根据编号查排名情况。
}
}
sort(a, a + n, cmp4); //按奖牌人口比例排序
for (int i = 0; i < n; i++) {
if (i > 0 && a[i].jiap == a[i - 1].jiap) {
a[i].pai = a[i - 1].pai;
} else a[i].pai = i + 1;
}
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
if (b[i].num == a[j].num)b[i].s4 =
a[j].pai; // 2,解决根据编号查排名情况。
}
}
for (int i = 0; i < m; i++) {
int mind = n + 1, flag;
if (mind > b[i].s1) {
mind = b[i].s1;
flag = 1;
}
if (mind > b[i].s2) {
mind = b[i].s2;
flag = 2;
}
if (mind > b[i].s3) {
mind = b[i].s3;
flag = 3;
}
if (mind > b[i].s4) {
mind = b[i].s4;
flag = 4;
}
cout << mind << ":" << flag << endl;
}
}
}