#P13822. 「Diligent-OI R2 B」白露为霜

「Diligent-OI R2 B」白露为霜

Description

A sequence a1,a2,,ana_1,a_2,\dots,a_n is called a polyline if and only if for i=1,2,,n1i=1,2,\dots,n-1, the condition aiai+1=1|a_i-a_{i+1}|=1 is satisfied. Specifically, a sequence of length 11 is also considered a polyline.

Given nn and two sequences aa and bb of length nn, where both aa and bb are polylines, you can perform the following operation on aa any number of times:

Choose an integer 1in1\le i\le n and modify aia_i to any value, but you must ensure that after the modification, the sequence aa remains a polyline.

The question is: Can you make aa equal to bb? Note: You do not need to print the operation steps.

Input Format

Note that this problem requires efficient input and output methods.

The input consists of multiple test cases. The first line contains TT, the number of test cases.

For each test case:

The first line contains nn.

The second line contains nn integers a1,a2,,ana_1,a_2,\dots,a_n.

The third line contains nn integers b1,b2,,bnb_1,b_2,\dots,b_n.

Output Format

For each test case, output one line. If it is impossible to make aa equal to bb, output No; otherwise, output Yes. Note: You do not need to print the operation steps.

3
1
1
2
4
1 2 3 4
3 2 3 2
2
1 2
2 1
Yes
Yes
No

Hint

Sample #1 Explanation

First test case: {1}{2}\{1\}\rarr\{2\}.

Second test case: {1,2,3,4}{3,2,3,4}{3,2,3,2}\{1,2,3,4\}\rarr\{3,2,3,4\}\rarr\{3,2,3,2\}.

Third test case: It can be proven that there is no solution.

Data Range

Let NN be the sum of nn across all test cases in a single test point.

For 100%100\% of the data, $1\le T\le10^6,1\le n\le10^6,1\le N\le10^6,1\le a_i\le10^9$.

  • Testcase 1: n=1n=1.
  • Testcase 2: n2n\le2.
  • Testcase 3: T5,n4,ai,bi4T\le 5,n\le 4,a_i,b_i\le4.
  • Testcase 4: For any 1in1\le i\le n, bi=ai+1b_i=a_i+1.
  • Testcase 5: No additional constraints.