cho.sh
Notes
Loading...

Pancake Love 2

Time limit

1s

Memory limit

128 MB

Problem

Eunju wants to make as many pancakes as possible from the ingredients she has.

Each pancake needs one piece of batter before it can be cooked. With 8 cups of milk, 8 egg yolks, 4 spoons of sugar, 1 spoon of salt, and 9 cups of flour, she can make 16 pieces of pancake batter. For any real number x >= 0, if every basic ingredient she has is at least x times the amount above, then she can make ⌊16x⌋ pieces of batter.

One piece of batter becomes one pancake by adding exactly one of the topping combinations below and cooking it.

  • Banana pancake: 1 banana
  • Strawberry pancake: 30 grams of strawberry jam
  • Chocolate pancake: 25 grams of chocolate spread
  • Walnut pancake: 10 walnuts
  • Extra-chocolate banana pancake: 3/4 banana and 10 grams of chocolate spread
  • Extra-chocolate walnut pancake: 10 grams of chocolate spread and 7 walnuts
  • Mix-mix pancake: 1/3 banana, 5 grams of strawberry jam, 5 grams of chocolate spread, and 3 walnuts

Bananas may be split into pieces or combined from pieces. For example, three 1/3-banana pieces can be combined to make one banana pancake.

For each test case, find the maximum number of pancakes Eunju can make.

Input

The first line contains the number of test cases T. Test cases may be separated by blank lines, and each test case consists of two lines.

The first line of each test case contains five integers cm, y, ssu, ssa, and f. They mean Eunju has cm cups of milk, y egg yolks, ssu spoons of sugar, ssa spoons of salt, and f cups of flour.

The second line contains four integers b, gs, gc, and w. They mean Eunju has b bananas, gs grams of strawberry jam, gc grams of chocolate spread, and w walnuts.

Every amount is an integer between 0 and 10^6, inclusive.

Output

For each test case, output one integer on its own line: the maximum number of pancakes Eunju can make.