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