Under construction

Still being built. Things may change

Moonlight Farm

Time limit8sMemory limit512 MB

Summary
For each crop dataset, compute income per unit time from seed cost, growth stages, fruit yield, and harvest count, then list names by descending efficiency with ties broken alphabetically.
Level

Easy3 of 10

Topics
Sorting, Implementation, Math, Simulation
Solved
No attempts yet

Problem

You are absorbed in the hit web game "Moonlight Farm". The goal of the game is to grow crops in fields, sell them for income, and use that income to expand your farm.

You want to expand your fields quickly. To start, you decide to rank the crops you can grow in the game by their income efficiency per unit time.

To grow a crop you must buy a seed. The seed of crop i has name Li and price Pi. When you plant a seed in a field, a sprout appears after Ai time. After the sprout appears, a young leaf appears after Bi time. After the young leaf appears, the leaves grow thick after Ci time. After the leaves grow thick, a flower blooms after Di time. After the flower blooms, fruit forms after Ei time. One seed yields Fi fruits, and each fruit sells for price Si. Some crops are multi-harvest, bearing fruit a total of Mi times. A single-harvest crop is represented by Mi = 1. A multi-harvest crop returns to the leaf stage after the fruit forms, until the Mi-th fruit forms. The income of a seed is the amount earned by selling all the fruits that grew from that seed minus the price of the seed. The income efficiency of a seed is that income divided by the time from planting the seed until all fruits have finished forming.

Your job is to write a program that, given crop information as input, sorts the crops in descending order of income efficiency and outputs them.

Input

The input is a sequence of datasets, each given in the following format.

N
L1 P1 A1 B1 C1 D1 E1 F1 S1 M1
L2 P2 A2 B2 C2 D2 E2 F2 S2 M2
...
LN PN AN BN CN DN EN FN SN MN

The first line is the number of crops N in the dataset (1 ≤ N ≤ 50).

The following N lines each contain the information for one crop. The meaning of each variable is as described in the problem. The crop name Li is a string of at most 20 lowercase letters, and 1 ≤ Pi, Ai, Bi, Ci, Di, Ei, Fi, Si ≤ 100, 1 ≤ Mi ≤ 5. You may assume that no two crops in a case share the same name.

The end of the input is marked by a line containing only a zero.

Output

For each dataset, output the crop names one per line in descending order of income efficiency. For crops with the same income efficiency, output their names in ascending lexicographic order.

After the output for each dataset, print a single line consisting only of "#".

Examples1

  1. Example 1

    Input
    5
    apple 1 1 1 1 1 1 1 10 1
    banana 1 2 2 2 2 2 1 10 1
    carrot 1 2 2 2 2 2 1 10 2
    durian 1 3 3 3 3 3 1 10 1
    eggplant 1 3 3 3 3 3 1 100 1
    4
    enoki 1 3 3 3 3 3 1 10 1
    tomato 1 3 3 3 3 3 1 10 1
    potato 1 3 3 3 3 3 1 10 1
    onion 1 3 3 3 3 3 1 10 1
    3
    a 10 1 1 1 1 1 1 10 1
    b 10 2 2 2 2 2 2 10 1
    c 10 2 2 2 2 2 2 10 1
    0
    
    Expected output
    eggplant
    apple
    carrot
    banana
    durian
    #
    enoki
    onion
    potato
    tomato
    #
    b
    c
    a
    #