#include <iostream>
#include <string>

using namespace std;

void swapD(double *a,double *b){
	double tmp = *a;
	*a = *b;
	*b = tmp;
}

void swapString(string *a,string *b){
	string tmp = *a;
	*a = *b;
	*b = tmp;
}

int main(){
	int n;
	string str[60];
	double data[60];
	for(int i=0;i<60;i++){
		data[i]=10000000;
	}

	while(cin>>n){
		if(n==0)break;

	for(int i=0;i<n;i++){
		data[i]=0;
		int p,a,b,c,d,e,f,s,m;

		cin>>str[i]>>p>>a>>b>>c>>d>>e>>f>>s>>m;

		int cnt=0;

		cnt = a+b+c+d+e;
		data[i]=s*f;
		m--;
		for(int j=0;j<m;j++){
			cnt+=(d+e);
			data[i]+=f*s;		}

		data[i]-=p;

		data[i]/=(double)cnt;
	}

	for(int i=0;i<n;i++){
		for(int j=n-1;j>i;j--){
			if(data[j]>=data[j-1] ){
				swapD(&data[j],&data[j-1]);
				swapString(&str[j],&str[j-1]);
			}
		}
	}

	for(int i=0;i<n;i++){
		for(int j=n-1;j>i;j--){
			if(data[j]>=data[j-1] && str[j]<=str[j-1]){
				swapD(&data[j],&data[j-1]);
				swapString(&str[j],&str[j-1]);
			}
		}
	}


	for(int i=0;i<n;i++){
		//cout<<str[i]<<" "<<data[i]<<endl;
		cout<<str[i]<<endl;
	}

	cout<<"#"<<endl;
	}


	return 0;
}
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

int main() {

    int h, w, a, b;
    cin >> h >> w >> a >> b;

    vector<vector<int>> grid(h, vector<int>(w, 0));
    rep(y, h) rep(x, w) {
            if ((y < b && x < a) || (b <= y && a <= x)) {
                grid[y][x] = 1;
            }
        }

    rep(y, h) {
        rep(x, w) {
            cout << grid[y][x];
        }
        cout << endl;
    }
}
