#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <map>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;
typedef long long ll;

int main()
{
    int n;
    while(cin >> n && n) {

        vector<pair<double,string> > v;
        map<double,vector<string> > ma;
        rep(i,n) {
            string l;
            int p,a,b,c,d,e,f,s,m;
            cin >> l >> p >> a >> b >> c >> d >> e >> f >> s >> m;

            double sum = a + b + c + d + e;
            sum += (m-1) * (d + e);
            int num = f*s*m - p;

            v.push_back(make_pair(num/sum,l));
            ma[num/sum].push_back(l);
        }

        vector<string> ans;
        map<double,vector<string> >::iterator ite;
        for(ite = ma.begin();ite != ma.end();ite++) {
            sort(ite->second.begin(),ite->second.end(),greater<string>());
            rep(i,ite->second.size()) {
                ans.push_back(ite->second[i]);
                // cout << ite->first << " " << ite->second[i] << endl;
            }
        }

        reverse(ans.begin(),ans.end());
        rep(i,ans.size()) cout << ans[i] << endl;

        cout << "#" << endl;

    }

    return 0;
}
#include <bits/stdc++.h>

using namespace std;

using ll = long long;

int main() {
  const int sqrtN = 512;
  const ll inf = (1LL<<31)-1;
  int n, q;
  cin >> n >> q;
  int bucket_sz = (n+sqrtN-1)/sqrtN;
  vector<ll> a(n, inf);
  vector<ll> bucketUp(bucket_sz, 0);
  vector<bool> bucketFlag(bucket_sz, false);
  auto push = [&](int k) {
    bucketFlag[k] = false;
    int l = k*sqrtN, r = (k+1)*sqrtN;
    for(int i = l; i < r; ++i) a[i] = bucketUp[k];
  };
  auto update = [&](int s, int t, int x) {
    for(int i = 0; i < bucket_sz; ++i) {
      int l = i*sqrtN, r = (i+1)*sqrtN;
      if(r <= s || t <= l) continue;
      if(s <= l && r <= t) {
	bucketUp[i] = x;
	bucketFlag[i] = true;
      } else {
	if(bucketFlag[i]) push(i);
	for(int j = max(s, l); j < min(t, r); ++j) {
	  a[j] = x;
	}
      }
    }
  };
  auto get = [&](int k)->ll{
    if(bucketFlag[k/sqrtN]) push(k/sqrtN);
    return a[k];
  };
  while(q--) {
    int t;
    cin >> t;
    if(t == 0) {
      ll s, t, x;
      cin >> s >> t >> x;
      update(s, t+1, x);
    } else {
      int k;
      cin >> k;
      cout << get(k) << endl;
    }
  }

  return 0;
}

