//第二次网络预赛
/*
6 3
radish 1 10 15
rose 1 18 23
watermelon 2 28 13 23
grapefruit 3 61 26 39
pitaya 4 70 29 41
blueberry 5 31 14 18
*/
#include<iostream>
#include<string>
#include<fstream>
#include<algorithm>
#include<set>
using namespace std;
struct plant //typedef
{
string name;
double sum;
bool operator>(const plant &a) const
{
return a.sum>sum;
}
};
/*
struct cmp
{
bool (const double &a,const double &b)
{
if(a!=b)
return a>b;
else
{
return a>b;
}
}
};
void Swap(double &m,double &n)
{
int temp = m;
m = n;
n = temp;
}
void Qsort(double *a,int m,int n)
{
if(m<n)
{
int i = m;
int j = n+1;
double temp = a[m];//选第一个元素为参考
while(1)
{
i++;
while(a[i] < temp) i++;
j-=1;
while(a[j] > temp) j--;
if(i < j) Swap(a[i],a[j]);
else break;
}
a[m] = a[j];
a[j] = temp;
Qsort(a,m,j-1);
Qsort(a,j+1,n);
}
}
*/
int main()
{
ifstream cin("c.in");
int n,m;
set<plant>s;
// double sarr[1000];
plant plan;//[1000];
cin>>n;
cin>>m;
for(int i=0;i<n;i++)
{
cin>>plan.name;//-
// string na;
// cin>>na;
// plan.insert(na);
int k;
cin>>k;
if(k==1)
{
int ji,yan;
cin>>ji;
cin>>yan;
plan.sum=(double)yan/ji;//-
}
else
{
int k1,k2;
cin>>k1;
cin>>k2;
int yan;
cin>>yan;
if(k%2==0)
{
plan.sum=(double)(yan*k)/(k1*k/2+k2*k/2);//-
}
else
{
plan.sum=(double)(yan*k)/(k1*(k/2+1)+k2*k/2);//-
}
}
// sarr[i]=plan[i].sum;
// cout<<sarr[i]<<" ";
s.insert(plan);
set<plant>::iterator it;
for(it=s.begin();it<s.end();it++)
{
cout<<(*it).name<<endl;
}
}
cout<<endl;
/*
// Qsort(plan.sum,0,n);
for(int i=0;i<n;i++)
{
cout<<plan[i].name<<" ";
}
*/
return 0;
}