Gift Before Tax

Given progressive tax bands and each friend's prior income, find the smallest pre-tax gift that leaves the friend with exactly the required after-tax amount.

Medium6Binary searchMathImplementationNo attempts yetTime limit2sMemory limit512 MB

Problem

George has won the lottery and wants to share the money with his friends. A gift is taxed once it gets large enough, and the tax depends on how much the friend has already earned that year.

Tax is worked out with tax bands. The bands start at zero and follow one another. Each band taxes the part of the income that falls inside it at its own rate. The last band applies to all income above the sum of the sizes of the other bands.

If a friend has already earned ee this year and George hands over a pre-tax amount gg, that friend's income for the year rises from ee to e+ge+g. The tax due is the total tax on income e+ge+g minus the total tax on income ee, and the friend keeps gg minus that tax.

You are given the number of tax bands, how much each friend has earned, and how much each friend has to keep after tax. Work out how much George gives each friend before tax.

Input

  • One line with an integer BB (1B201 \le B \le 20), the number of tax bands.
  • BB lines, each with two real numbers sis_i (0<si1060 < s_i \le 10^6) and pip_i (0pi1000 \le p_i \le 100): the size in pounds of the ii-th tax band and its tax rate in percent.
  • One line with a real number PP (0P99.9990 \le P \le 99.999), the tax rate in percent on all income above the bands.
  • One line with an integer FF (0<F200 < F \le 20), the number of friends.
  • FF lines, each with two real numbers eje_j and mjm_j (0ej1060 \le e_j \le 10^6, 0<mj1060 < m_j \le 10^6): what the jj-th friend has earned, and what that friend has to keep after tax.

The tax bands are given from the lowest band to the highest.

Output

Print FF lines, one per friend, in the order the friends are given.

Each line holds the pre-tax amount George gives that friend, rounded to exactly six decimal places. When several amounts leave the friend with exactly mjm_j, print the smallest one.