#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>

using namespace std;
typedef long long ll;
ll a[1005][1005];
int n;
int pri[10005],tot;
bool mk[10005];
ll lcm(ll a,ll b) {
	if((!a)||(!b)) return a+b;
	return 1ll*a/__gcd(a,b)*b;
}
int main() {
	scanf("%d",&n);
	if(n==2) {
		printf("4 7\n23 10");
		return 0;
	}
	mk[1] = mk[0] = 1;
	for(int i=2;i<=10000;i++) {
		if(!mk[i]) { pri[++tot]=i; }
		if(tot==1000) break;
		for(int j=1;j<=tot&&1ll*pri[j]*i<=10000;j++) {
			int k = pri[j] * i;
			mk[k] = 1;
			if(i%pri[j]==0) break;
		}
	}
	for(int i=1;i<=n;i++) {
		for(int j=1;j<=n;j++) {
			if((i+j)%2==0) a[i][j] = pri[(i + j) / 2] * pri[n+((i-j)/2+(n+1)/2)];
		}
	}
	for(int i=1;i<=n;i++) {
		for(int j=1;j<=n;j++) {
			if((i+j)%2==1) a[i][j] = lcm( lcm(a[i-1][j],a[i+1][j]),lcm(a[i][j-1],a[i][j+1]) ) + 1;
			printf("%lld ",a[i][j]);
		}
		puts("");
	}
}
#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
using mii=map<int,int>;
using pii=pair<int,int>;
using vlai=valarray<int>;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
struct item{
    string name;
    int p,s1,s2,x,r,m;
    double y;
    item(){
        int a,b,c,d,e;
        cin>>name>>p>>a>>b>>c>>d>>e>>x>>r>>m; 
        s1=a+b+c;s2=d+e;
        y=(double)(x*r*m-p)/(s1+s2*m);
    }
};

int main(){
    int n;
    while(cin>>n,n){
        vector<item> v(n);
        sort(all(v),[](item a, item b){return a.y>b.y || (a.y==b.y && a.name<b.name);});
        for(auto p : v)cout<<p.name<<endl;
        cout<<"#"<<endl;
    }
}