Increasing Xor Sequence

All submissions for this problem are available.
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
You are given a sequence of n integers a_{1}, ..., a_{n}. Count the number of sequences b = b_{1}, ..., b_{n} such that: 0 ≤ b_{1} ≤ ... ≤ b_{n} < 2^{31} and (a_{1} XOR b_{1}) ≤ … ≤ (a_{n} XOR b_{n}). Return this count, modulo 10^{9}+7.
Here XOR denotes the bitwise XOR.
Input
The first line of input will contain an integer T, the number of test cases.
Each test case will be in two lines.
The first line of the case will contain an integer n.
The next line of the case will contain n space separated integers a_{1},...,a_{n}.
Output
Output a single number, the number of sequences, modulo 10^{9}+7.
Constraints
 1 ≤ T ≤ 100
 1 ≤ n ≤ 5
 0 ≤ a_{i} < 2^{31}
Example
Input: 4 1 42 5 5 4 3 2 1 4 1194533513 122420337 1448417648 120078455 3 31 2047 2147483647 Output: 147483634 986095186 0 468598063
Explanation
In the first case, there are 2^{31} possible sequences, so the answer is 2^{31} modulo 10^{9}+7 = 147483634
For the second case, one possible example of a valid sequence is b = 9, 9, 18, 19, 32. We can check that this sequence is nondecreasing, and also, we have (a_{1} XOR b_{1}) = 12, (a_{2} XOR b_{2}) = 13, (a_{3} XOR b_{3}) = 17, (a_{4} XOR b_{4}) = 17, (a_{5} XOR b_{5}) = 33, which is also nondecreasing.
For the third case, no sequences satisfy the conditions.
Author:  lg5293 
Tester:  errichto 
Editorial  https://discuss.codechef.com/problems/INCXOR 
Tags  bitmasks, cook80, digitdp, lg5293, mediumhard 
Date Added:  13032017 
Time Limit:  1 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, SCM chicken, PYP3, CLOJ, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
HELP
If you are still having problems, see a sample solution here. 
///