#include <iostream>
using namespace std;
const int N = 10;
int temp[N][3];//金牌数、奖牌数、人口数
int main() {
int n, m;
while(scanf("%d%d", &n, &m) != EOF){
for(int i = 0; i < n; i ++){
scanf("%d%d%d", &temp[i][0], &temp[i][1], &temp[i][2]);
}
//注意是float类型,不能是整型
float num[N][4];//金牌总数 < 奖牌总数 < 金牌人口比例 < 奖牌人口比例
int ranks[N][4] = {0};//四个排名
for(int i = 0; i < m; i ++){
int countryId;
cin >> countryId;
num[i][0] = temp[countryId][0];
num[i][1] = temp[countryId][1];
num[i][2] = temp[countryId][0]?1.0 * temp[countryId][0] / temp[countryId][2]:0;
num[i][3] = temp[countryId][1]?1.0 * temp[countryId][1] / temp[countryId][2]:0;//注意转成float再做除法
}
for(int i = 0; i < m; i ++){
for(int j = 0; j < m; j ++){
for(int k = 0; k < 4; k ++){
if (num[i][k] < num[j][k]) {
ranks[i][k] ++;
}
}
}
}
for(int i = 0; i < m; i ++){
int min = 0;
for(int k = 1; k < 4; k ++){
if(ranks[i][k] < ranks[i][min])
min = k;
}
cout << ranks[i][min] + 1 << ":" << min + 1 << endl;
}
cout << endl;
}
return 0;
}
// 64 位输出请用 printf("%lld")