Chefina has two sequences $A_1, A_2, \ldots, A_N$ and $B_1, B_2, \ldots, B_N$. She views two sequences with length $N$ as identical if, after they are sorted in non-decreasing order, the $i$-th element of one sequence is equal to the $i$-th element of the other sequence for each $i$ ($1 \le i \le N$).
To impress Chefina, Chef wants to make the sequences identical. He may perform the following operation zero or more times: choose two integers $i$ and $j$ $(1 \le i,j \le N)$ and swap $A_i$ with $B_j$. The cost of each such operation is $\mathrm{min}(A_i, B_j)$.
You have to find the minimum total cost with which Chef can make the two sequences identical.

-----Input-----
- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
- The first line of each test case contains a single integer $N$.
- The second line contains $N$ space-separated integers $A_1, A_2, \ldots, A_N$.
- The third line contains $N$ space-separated integers $B_1, B_2, \ldots, B_N$.

-----Output-----
For each test case, print a single line containing one integer ― the minimum cost, or $-1$ if no valid sequence of operations exists.

-----Constraints-----
- $1 \le T \le 2,000$
- $1 \le N \le 2 \cdot 10^5$
- $1 \le A_i, B_i \le 10^9$ for each valid $i$
- the sum of $N$ over all test cases does not exceed $2 \cdot 10^6$

-----Subtasks-----
Subtask #1 (15 points):
- $T \le 20$
- $N \le 20$
Subtask #2 (85 points): original constraints

-----Example Input-----
3
1
1
2
2
1 2
2 1
2
1 1
2 2

-----Example Output-----
-1
0
1

-----Explanation-----
Example case 1: There is no way to make the sequences identical, so the answer is $-1$.
Example case 2: The sequence are identical initially, so the answer is $0$.
Example case 3: We can swap $A_1$ with $B_2$, which makes the two sequences identical, so the answer is $1$.

```python

USER_FILENAME = "<user_code>"
import sys, json, builtins
import math, heapq, bisect, itertools, functools, collections, statistics, fractions, decimal, operator, array, random, re, string, os, pathlib
try:
    import resource as _res
except Exception:
    _res = None
from collections import Counter, defaultdict, deque, OrderedDict
from functools import lru_cache, reduce
from itertools import accumulate, permutations, combinations, product
from math import gcd, ceil, floor, sqrt
from decimal import Decimal
try:
    from typing import *
except Exception:
    pass
try:
    sys.setrecursionlimit(1_000_000)
except Exception:
    pass
try:
    import site as _site
    try:
        _sys_sites = _site.getsitepackages() if hasattr(_site, "getsitepackages") else []
        for _p in _sys_sites:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
    try:
        _usp = _site.getusersitepackages()
        if isinstance(_usp, str):
            _usp = [_usp]
        for _p in _usp:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
except Exception:
    pass

ns = {"__name__": "__main__"}
for _k, _v in list(globals().items()):
    if not _k.startswith("_"):
        ns[_k] = _v
_CODE = '# cook your dish here\nt= int(input())\nfor _ in range(0,t):\n n=int(input())\n arr1= list(map(int, input().split()))\n arr2= list(map(int, input().split()))\n flag = False\n mini = 9999999999\n el = set()\n movefromA = []\n movefromB = []\n lengtha=lengthb=0\n\n number1 = {}\n number2 = {}\n for i in arr1:\n  if (i in number1):\n   number1[i] += 1\n  else:\n   number1[i] = 1\n   number2[i] = 0\n   el.add(i)\n\n for i in arr2:\n  if (i in number2):\n   number2[i] += 1\n  else:\n   number2[i] = 1\n   if i not in el:\n    number1[i] = 0\n    el.add(i)\n\n for i in el:\n  a = number1[i]\n  b = number2[i]\n  total = a + b\n  if total%2!=0:\n   flag = True\n   break\n\n  if(mini > i):\n   mini = i\n\n  if(a < b):\n   for j in range((b - a) >> 1):\n    movefromB.append(i)\n    lengthb += 1\n  elif(b < a):\n   for j in range((a - b) >> 1):\n    movefromA.append(i)\n    lengtha += 1\n\n if(lengtha != lengthb):\n  flag = True\n\n if(flag):\n  print(-1)\n  continue\n\n movefromA.sort()\n movefromB.sort()\n\n mini *= 2\n\n lessMinA = 0\n lessMinB = 0\n for i in movefromA:\n  if i > mini:\n   break\n  lessMinA += 1\n greatMinA = lengtha - lessMinA\n\n for i in movefromB:\n  if i > mini:\n   break\n  lessMinB += 1\n greatMinB = lengthb - lessMinB\n\n pay = 0\n\n if(lessMinA <= greatMinB):\n  for i in movefromA[:lessMinA]:\n   pay += i\n  for i in movefromB[:lessMinB]:\n   pay += i\n  pay += (mini * (greatMinA - lessMinB))\n\n else:\n  for i in movefromA[:(greatMinB)]:\n   pay += i\n  for i in movefromB[:(greatMinA)]:\n   pay += i\n\n  i = greatMinB\n  j = greatMinA\n  for k in range(lessMinB - greatMinA):\n   if(movefromA[i] < movefromB[j]):\n    pay += movefromA[i]\n    i += 1\n   else:\n    pay += movefromB[j]\n    j += 1\n\n\n print(pay)'
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

```

Measured memory_bytes: 14215