CF2131C.Make it Equal

传统题 时间 2000 ms 内存 256 MiB 5 尝试 1 已通过 1 标签

Make it Equal

Given two multisets SS and TT of size nn and a positive integer kk, you may perform the following operations any number (including zero) of times on SS:

  • Select an element xx in SS, and remove one occurrence of xx in SS. Then, either insert x+kx+k into SS, or insert xk|x-k| into SS.

Determine if it is possible to make SS equal to TT. Two multisets SS and TT are equal if every element appears the same number of times in SS and TT.

Input

Each test contains multiple test cases. The first line contains an integer tt (1t1041 \le t \le 10^4) — the number of test cases. The description of the test cases follows.

The first line contains two integers nn and kk (1n21051 \le n \le 2 \cdot 10^5, 1k1091 \le k \le 10^9) — the size of SS and the constant, respectively.

The second line contains nn integers S1,S2,,SnS_1,S_2,\ldots,S_n (0Si1090 \le S_i \le 10^9) — the elements in SS.

The third line contains nn integers T1,T2,,TnT_1,T_2,\ldots,T_n (0Ti1090 \le T_i \le 10^9) — the elements in TT.

It is guaranteed that the sum of nn over all test cases does not exceed 21052 \cdot 10^5.

Output

For each test case, output "YES" if it is possible to make SS equal to TT, and "NO" otherwise.

You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses.

Note

In the first test case, we can remove one occurrence of 11 from SS and insert 1k=13=2|1-k|=|1-3|=2 into SS, making SS equal to TT.

In the second test case, we can remove one occurrence of 44 from SS and insert 4+k=4+8=124+k=4+8=12 into SS, making SS equal to TT.

In the last test case, we can show that it is impossible to make SS equal to TT.

Samples

5
1 3
1
2
1 8
4
12
3 5
6 2 9
8 4 11
2 7
2 8
2 9
3 2
0 1 0
1 0 1
YES
YES
YES
NO
NO

在线编程 IDE

建议全屏模式获得最佳体验