This page is still under construction.

Parts of this page are still being built. What you see may change.

Cabbage

Time limit1sMemory limit256 MB

Summary
Each child eats only one cabbage variety; given initial stocks, per-variety prices, and a shared budget, find the largest equal portion each child can receive.
Level

Medium6 of 10

Topics
Binary search, Greedy, Math, Implementation
Solved
No attempts yet

Problem

The <> Children of the Volga Plain are known to be very fond of pickled cabbage. However, each of them has a favorite cabbage variety and will not eat any other kind. The preferences seem to be random. Different Children can like either different or the same varieties of cabbage. To make everyone happy, the portions must be the same. Alchen, the chief, wants to make the portions as big as possible.

Initially, Alchen has a certain stock of each cabbage variety and a certain sum of money. He can buy extra cabbage with this money, a different amount of each variety. The prices are known. However, he cannot sell the cabbage he already has.

Help Alchen figure out the best portion sizes for his proteges.

Input

The first line of the input file contains a single integer TT, the number of test cases (1≤T≤1001 \le T \le 100). It is followed by TT blocks.

The first line of a block contains three integers: NN, the number of pickled cabbage varieties (1≤N≤1051 \le N \le 10^5), MM, the number of hungry Children (1≤M≤1051 \le M \le 10^5), and SS, the sum of money allocated for buying extra pickled cabbage (1≤S≤1091 \le S \le 10^9).

The second line of a block contains MM integers T_iT\_i, where T_iT\_i is the number of the pickled cabbage variety preferred by the ii-th Child of the Volga Plain (1≤T_i≤N1 \le T\_i \le N).

Each of the following NN lines contains two integers: A_iA\_i, the initially available amount of cabbage of the ii-th variety, in kilograms (0≤A_i≤1040 \le A\_i \le 10^4), and C_iC\_i, the price of a kilogram of cabbage of this variety (1≤C_i≤1041 \le C\_i \le 10^4).

The sum of MM over all test cases is at most 10510^5, and the sum of NN over all test cases is at most 10510^5.

Output

The output file must contain TT lines, and the ii-th line must contain the answer to the ii-th test case. The answer to a test is the maximum possible portion size, in kilograms.

The absolute or relative error of each answer must be at most 10−910^{-9}.

Examples2

  1. Example 1

    Input
    1
    3 7 37
    3 3 2 3 1 2 3
    2 2
    1 6
    3 1
    
    Expected output
    2.777777777778
    
  2. Example 2

    Input
    2
    2 3 17
    1 2 1
    50 3
    0 2
    1 2 1
    1 1
    1 1
    
    Expected output
    8.5
    1