{"trustable":true,"prependHtml":"\u003cscript\u003e window.katexOptions \u003d { disable: true }; \u003c/script\u003e\n\u003cscript type\u003d\"text/x-mathjax-config\"\u003e\n MathJax.Hub.Config({\n tex2jax: {\n inlineMath: [[\u0027$$$\u0027,\u0027$$$\u0027], [\u0027$\u0027,\u0027$\u0027]],\n displayMath: [[\u0027$$$$$$\u0027,\u0027$$$$$$\u0027], [\u0027$$\u0027,\u0027$$\u0027]]\n }\n });\n\u003c/script\u003e\n\u003cscript async src\u003d\"https://mathjax.codeforces.org/MathJax.js?config\u003dTeX-AMS-MML_HTMLorMML\" type\u003d\"text/javascript\"\u003e\u003c/script\u003e","sections":[{"title":"","value":{"format":"HTML","content":"\u003cdiv class\u003d\"panel_content\"\u003ePeople in love always feel humble. Sometimes, Rikka is worried about whether she deserves love from Yuta.\u003cbr\u003e\u003cbr\u003eStable marriage problem is an interesting theoretical model which has a strong connection with the real world. Given $n$ men and $n$ women, where each person has ranked all members of the opposite sex in order of preference. We use a permutation $p$ of length $n$ to represent a match that the $i$th man gets married with the $p_i$th woman. A match is stable if and only if there are no two people of opposite sexes who would both rather have each other than their current partners, i.e., $\\forall i \\neq j, \\neg (r_i(p_j,p_i) \\wedge r_{p_j}(i,j))$ where $r_a(b,c)$ represents whether person $a$ loves $b$ more than $c$.\u003cbr\u003e\u003cbr\u003eRikka wants to resolve the confusion in her mind by considering a special case of the stable marriage problem. Rikka uses a feature integer to represents a person\u0027s character, and for two persons with feature integers equal to $x$ and $y$, Rikka defines the suitable index of them as $x \\oplus y$, where $\\oplus$ represents binary exclusive-or.\u003cbr\u003e\u003cbr\u003eGiven $n$ men with feature integers $a_1, \\dots, a_n$ and $n$ women with feature integers $b_1, \\dots, b_n$. For the $i$th man, he loves the $j$th woman more than the $k$th woman if and only if $a_i \\oplus b_j \u0026gt; a_i \\oplus b_k$; for the $i$th woman, she loves the $j$th man more than the $k$th man if and only if $b_i \\oplus a_j \u0026gt; b_i \\oplus a_k$. \u003cbr\u003e\u003cbr\u003eRikka wants to calculate the best stable match for this problem, i.e., let $\\mathbb P$ be the set of all stable match, she wants to calculate $\\max_{p \\in \\mathbb P} \\left(\\sum_{i\u003d1}^n \\left(a_i \\oplus b_{p_i} \\right) \\right)$. Since $n$ is quite large, this problem is too difficult for Rikka, could you please help her find the answer?\u003c/div\u003e"}},{"title":"Input","value":{"format":"HTML","content":"The first line of the input contains a single integer $T(1 \\leq T \\leq 50)$, the number of test cases.\u003cbr\u003e\u003cbr\u003eFor each test case, the fisrt line contains a sigle integer $n(1 \\leq n \\leq 10^5)$. \u003cbr\u003e\u003cbr\u003eThe second line contains $n$ integers $a_1, \\dots, a_n(1 \\leq a_i \\leq 10^9)$ which represents the feature number of each man. \u003cbr\u003e\u003cbr\u003eThe third line contains $n$ integers $b_1, \\dots, b_n(1 \\leq b_i \\leq 10^9)$ which represents the feature number of each woman.\u003cbr\u003e\u003cbr\u003eThe input guarantees that there are no more than $5$ test cases with $n \u0026gt; 10^4$, and for any $i,j \\in [1,n], i \\neq j$, $a_i \\neq a_j$ and $b_i \\neq b_j$."}},{"title":"Output","value":{"format":"HTML","content":"For each test case, output a single line with a single integer, the value of the best stable match. If there is no stable match, output $-1$.\u003cbr\u003e\u003cbr\u003e\u003cdiv style\u003d\"font-family:Times New Roman;font-size:14px;background-color:F4FBFF;border:#B7CBFF 1px dashed;padding:6px\"\u003e\u003cdiv style\u003d\"font-family:Arial;font-weight:bold;color:#7CA9ED;border-bottom:#B7CBFF 1px dashed\"\u003e\u003ci\u003eHint\u003c/i\u003e\u003c/div\u003eIn the first test case, one of the best matches is $(2,1,4,3)$. Therefore the answer is $(1 \\oplus 2) + (2 \\oplus 1) + (3 \\oplus 4) + (4 \\oplus 3) \u003d 20$.\u003c/div\u003e"}},{"title":"Sample","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e2\r\n4\r\n1 2 3 4\r\n1 2 3 4\r\n5\r\n10 20 30 40 50\r\n15 25 35 45 55\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e20\r\n289\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}