{"trustable":true,"prependHtml":"\u003cstyle type\u003d\u0027text/css\u0027\u003e\n .input, .output {\n border: 1px solid #888888;\n }\n .output {\n margin-bottom: 1em;\n position: relative;\n top: -1px;\n }\n .output pre, .input pre {\n background-color: #EFEFEF;\n line-height: 1.25em;\n margin: 0;\n padding: 0.25em;\n }\n \u003c/style\u003e\n \u003clink rel\u003d\"stylesheet\" href\u003d\"//codeforces.org/s/96598/css/problem-statement.css\" type\u003d\"text/css\" /\u003e\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 type\u003d\"text/javascript\" async src\u003d\"https://mathjax.codeforces.org/MathJax.js?config\u003dTeX-AMS_HTML-full\"\u003e\u003c/script\u003e","sections":[{"title":"","value":{"format":"HTML","content":"\u003cp\u003eA sequence of $$$n$$$ non-negative integers ($$$n \\ge 2$$$) $$$a_1, a_2, \\dots, a_n$$$ is called good if for all $$$i$$$ from $$$1$$$ to $$$n-1$$$ the following condition holds true: $$$$$$a_1 \\: \\\u0026amp; \\: a_2 \\: \\\u0026amp; \\: \\dots \\: \\\u0026amp; \\: a_i \u003d a_{i+1} \\: \\\u0026amp; \\: a_{i+2} \\: \\\u0026amp; \\: \\dots \\: \\\u0026amp; \\: a_n,$$$$$$ where $$$\\\u0026amp;$$$ denotes the \u003ca href\u003d\"https://en.wikipedia.org/wiki/Bitwise_operation#AND\"\u003ebitwise AND operation\u003c/a\u003e.\u003c/p\u003e\u003cp\u003eYou are given an array $$$a$$$ of size $$$n$$$ ($$$n \\geq 2$$$). Find the number of permutations $$$p$$$ of numbers ranging from $$$1$$$ to $$$n$$$, for which the sequence $$$a_{p_1}$$$, $$$a_{p_2}$$$, ... ,$$$a_{p_n}$$$ is good. Since this number can be large, output it modulo $$$10^9+7$$$.\u003c/p\u003e"}},{"title":"Input","value":{"format":"HTML","content":"\u003cp\u003eThe first line contains a single integer $$$t$$$ ($$$1 \\leq t \\leq 10^4$$$), denoting the number of test cases.\u003c/p\u003e\u003cp\u003eThe first line of each test case contains a single integer $$$n$$$ ($$$2 \\le n \\le 2 \\cdot 10^5$$$)\u0026nbsp;— the size of the array.\u003c/p\u003e\u003cp\u003eThe second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \\ldots, a_n$$$ ($$$0 \\le a_i \\le 10^9$$$) — the elements of the array.\u003c/p\u003e\u003cp\u003eIt is guaranteed that the sum of $$$n$$$ over all test cases doesn\u0027t exceed $$$2 \\cdot 10^5$$$.\u003c/p\u003e"}},{"title":"Output","value":{"format":"HTML","content":"\u003cp\u003eOutput $$$t$$$ lines, where the $$$i$$$-th line contains the number of good permutations in the $$$i$$$-th test case modulo $$$10^9 + 7$$$.\u003c/p\u003e"}},{"title":"Examples","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\u003e4\n3\n1 1 1\n5\n1 2 3 4 5\n5\n0 2 0 3 0\n4\n1 3 5 1\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e6\n0\n36\n4\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}},{"title":"Note","value":{"format":"HTML","content":"\u003cp\u003eIn the first test case, since all the numbers are equal, whatever permutation we take, the sequence is good. There are a total of $$$6$$$ permutations possible with numbers from $$$1$$$ to $$$3$$$: $$$[1,2,3]$$$, $$$[1,3,2]$$$, $$$[2,1,3]$$$, $$$[2,3,1]$$$, $$$[3,1,2]$$$, $$$[3,2,1]$$$.\u003c/p\u003e\u003cp\u003eIn the second test case, it can be proved that no permutation exists for which the sequence is good.\u003c/p\u003e\u003cp\u003eIn the third test case, there are a total of $$$36$$$ permutations for which the sequence is good. One of them is the permutation $$$[1,5,4,2,3]$$$ which results in the sequence $$$s\u003d[0,0,3,2,0]$$$. This is a good sequence because \u003c/p\u003e\u003cul\u003e \u003cli\u003e $$$ s_1 \u003d s_2 \\: \\\u0026amp; \\: s_3 \\: \\\u0026amp; \\: s_4 \\: \\\u0026amp; \\: s_5 \u003d 0$$$, \u003c/li\u003e\u003cli\u003e $$$ s_1 \\: \\\u0026amp; \\: s_2 \u003d s_3 \\: \\\u0026amp; \\: s_4 \\: \\\u0026amp; \\: s_5 \u003d 0$$$, \u003c/li\u003e\u003cli\u003e $$$ s_1 \\: \\\u0026amp; \\: s_2 \\: \\\u0026amp; \\: s_3 \u003d s_4 \\: \\\u0026amp; \\: s_5 \u003d 0$$$, \u003c/li\u003e\u003cli\u003e $$$ s_1 \\: \\\u0026amp; \\: s_2 \\: \\\u0026amp; \\: s_3 \\: \\\u0026amp; \\: s_4 \u003d s_5 \u003d 0$$$. \u003c/li\u003e\u003c/ul\u003e\u003cp\u003e \u003c/p\u003e"}}]}