Under construction

Still being built. Things may change

Maximize the Minimum

Time limit4sMemory limit2048 MB

Summary
Given two arrays with per-element removal costs, find the largest possible minimum gap |a_i - b_j| across the remaining elements when total removal cost is at most s.
Level

Hard8 of 10

Topics
Binary search, Dynamic programming, Sorting
Solved
No attempts yet

Problem

You have an array aa of length nn and an array bb of length mm. You can choose to remove some elements from the arrays. Removing element aia_i costs cic_i coins, and removing element bjb_j costs djd_j coins. Importantly, there should be at least one element left in aa and at least one left in bb.

When you are done removing the elements, you compute the following value:

min⁡1≤i≤n1≤j≤m∣ai−bj∣\min_{\substack{1 \le i \le n \\ 1 \le j \le m}} |a_i - b_j|

You want to maximize this value. What is the maximum value you can get if you can spend at most ss coins in total?

Input

The first line contains an integer tt (1≤t≤2⋅1051 \le t \le 2 \cdot 10^5), the number of test cases. The test cases follow.

The first line of each test case contains integers nn (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5), mm (1≤m≤2⋅1051 \le m \le 2 \cdot 10^5) and ss (0≤s≤10180 \le s \le 10^{18}). The next four lines contain integer arrays aa, bb, cc, dd, in this order (−109≤ai,bj≤109-10^9 \le a_i, b_j \le 10^9; 1≤ci,dj≤10121 \le c_i, d_j \le 10^{12}). The arrays aa and cc have length nn. The arrays bb and dd have length mm.

The sum of nn over all test cases does not exceed 2⋅1052 \cdot 10^5. The sum of mm over all test cases does not exceed 2⋅1052 \cdot 10^5.

Output

For each test case, print the maximum possible value you can get.

Examples1

  1. Example 1

    Input
    2
    1 4 10
    15
    1 6 9 13
    8
    3 1 2 4
    5 4 4
    -1 5 3 2 -4
    -7 8 6 2
    2 3 1 1 2
    3 1 1 1
    
    Expected output
    14
    3