AT_arc201_d [ARC201D] Match, Mod, Minimize

Description

You are given sequences of non-negative integers $ A=(A_1,A_2,\dots ,A_N),B=(B_1,B_2,\dots ,B_N) $ of length $ N $ and a positive integer $ M $ . When the elements of $ A $ can be rearranged freely, find the minimum possible value of $ \max_{1\le i\le N} ((A_i+B_i) \bmod M) $ . $ T $ test cases are given, so find the answer for each.

Input Format

The input is given from Standard Input in the following format: > $ T $ $ \text{case}_1 $ $ \text{case}_2 $ $ \vdots $ $ \text{case}_T $ Each test case is given in the following format: > $ N $ $ M $ $ A_1 $ $ A_2 $ $ \ldots $ $ A_N $ $ B_1 $ $ B_2 $ $ \ldots $ $ B_N $

Output Format

Output $ T $ lines. The $ j $ -th line should contain the minimum possible value of $ \max_{1\le i\le N} ((A_i+B_i) \bmod M) $ for the $ j $ -th test case.

Explanation/Hint

### Sample Explanation 1 For the first test case, if we rearrange $ A $ to $ 4,3,1 $ , then $ (A_i+B_i) \bmod M $ becomes $ 0,3,2 $ respectively, and the $ \max $ of these is $ 3 $ . ### Constraints - $ 1 \le T \le 10^5 $ - $ 1 \le N \le 3 \times 10^5 $ - $ 1 \le M \le 10^9 $ - $ 0 \le A_i,B_i \lt M $ - The sum of $ N $ over all test cases is at most $ 3 \times 10^5 $ . - All input values are integers.