//比赛的时候卡了三个点。今天卡了两个点。真心不愿意再看了。
// 自己按照直线相交的思路的敲得。题意里说了不是按照final rank 给的。但是。这样就和标程输出不同。
//就是觉得AC突然就不那么重要了。也只是揣摩出题人的意思。好无聊。
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
using namespace std; int maxn = 0x1f1f1f1f;
int minn = ; int item[];
int fa[];
int a[];
int b[];
int num[];
int ac[]; int get(char s[])
{
int num = ;
int len = strlen(s);
for (int i=; i<len; ++i)
{
num = num * + s[i] - '';
}
return num;
} int main()
{
int t, p;
int ci;
char temp, time[];
while(~scanf("%d%d", &t, &p))
{
maxn = 0x1f1f1f1f;
minn = ;
if (t == && p == )
break;
memset(item, , sizeof(item));
memset(a, , sizeof(a));
memset(b, , sizeof(b));
memset(fa, , sizeof(fa));
memset(num, , sizeof(num));
memset(ac, , sizeof(ac)); for (int i=; i<t; ++i)
{
for (int j=; j<p; ++j)
{
scanf("%d", &ci);
getchar();
scanf("%s", time);
if (ci == )
continue;
if (time[] == '-')
continue;
else
{
item[i] += ;
int sco = get(time);
fa[i] += (sco + (ci - ) * );
a[i] += (ci-);
b[i] += sco;
num[i] = i+;
if (ci == )
ac[i] += ;
}
}
} for (int i=; i<t; ++i)
{
if (item[i] == ) continue;
if (fa[i] == ) continue;
for (int j=; j<t; ++j)
{
if (item[j] == ) continue;
if (item[i] != item[j]) continue;
if (a[i] == a[j]) continue;
if (fa[j] == ) continue;
double t = (b[i] - b[j]) * 1.0 / (a[j] - a[i]);
int rs, rb;
if (fa[i] > fa[j])
{
rs = j;
rb = i;
}
else if (fa[i] < fa[j])
{
rs = i;
rb = j;
}
else if (fa[i] == fa[j])
{
minn = maxn = ;
continue;
}
if (a[rs] > a[rb])
{
if (t<maxn)
{
if (t == int(t))
maxn = t - ;
else maxn = int(t);
}
if (num[rs] < num[rb] && t == int(t))
maxn += ;
}
else if (a[rs] < a[rb])
{
minn = int (t + );
if (num[rs] < num[rb] && t == int(t))
minn -= ;
}
}
}
if (minn <= )
minn = ;
printf("%d ", minn);
if (maxn == 0x1f1f1f1f)
{
printf("*\n");
}
else printf("%d\n", maxn);
}
return ;
}
LOoK