ZOJ3970 :Sequence to Sequence

时间限制:1000MS    内存限制:65536KByte   64位IO格式:%lld & %llu
描述

Chiaki has a sequence s1, s2, ..., sn. She would like to change it to another sequence t1, t2, ..., tn using the following operations:

Chiaki would like to know the minimum number of operations needed.

Input

There are multiple test cases. The first line of input contains an integer T, indicating the number of test cases. For each test case:

The first line contains an integer n (1 ≤ n ≤ 105) — the length of the sequence.

The second line contains n integers s1, s2, ..., sn (0 ≤ si ≤ 109).

The third line contains n integers t1, t2, ..., tn (0 ≤ ti ≤ 109).

It is guaranteed that the sum of n over all test cases does not exceed 106.

Output

For each test case, output an integer denoting the minimum number of operations. If it is impossible to change the sequence, output -1 instead.

Sample Input

2
5
1 1 1 1 1
2 0 2 0 2
7
3 1 2 3 2 1 4
2 0 0 0 0 0 2

Sample Output

3
3

Hint

For the first test case:

.
题目来源
The 14th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple
[提交] [状态]

|返回 |   | 转到页头|
Copyright @ 2008-2025 (浙ICP备2022001332号), TZOJ. All Rights Reserved.
2017-2025 台州市非普软件技术有限公司,浙江省台州市君悦大厦B幢1603室