Monisha likes to paint. She has painted $N$ paintings (numbered $1$ through $N$) and wants to choose some subset of these paintings for an exhibition. For each valid $i$, the $i$-th painting has beauty $b_i$ and the probability that it will be displayed at the exhibition is $p_i$. Each painting is chosen or excluded from the exhibition independently randomly.
The beauty of the resulting exhibition is the bitwise XOR of the beauties of all displayed paintings. If no paintings are displayed, the XOR is $0$.
Monisha wants to find out how beautiful her exhibition is going to be. Help her compute the expected value of the beauty of the exhibition.

-----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 $b_1, b_2, \ldots, b_N$.
- The third line contains $N$ space-separated real numbers $p_1, p_2, \ldots, p_N$. Each of these numbers is given with at most five digits after the decimal point.

-----Output-----
For each test case, print a single line containing one real number — the expected beauty of the exhibition. Your answer will be considered correct if its absolute or relative error does not exceed $10^{-6}$.

-----Constraints-----
- $1 \le N \le 10^5$
- $0 \le b_i \le 10^9$ for each valid $i$
- $0 \le p_i \le 1$ for each valid $i$
- the sum of $N$ over all test cases does not exceed $4 \cdot 10^5$

-----Example Input-----
2
3
5 6 2
1.0 0.0 0.5
4
2 2 2 2
0.5 0.5 0.5 0.5

-----Example Output-----
6.000000000000000
1.000000000000000

-----Explanation-----
Example case 1: The first painting must be displayed at the exhibition, the second one must be excluded. If the third painting is displayed (with probability $0.5$), the beauty is $5 \oplus 2 = 7$; if it is excluded (with probability $0.5$), the beauty is $5$. The expected beauty is $0.5 \cdot 5 + 0.5 \cdot 7 = 6$.
Example case 2: If there is an odd number of paintings at the exhibition, the beauty is $2$; this has a probability of $0.5$. If there is an even number of paintings, the beauty is $0$ (with probability $0.5$), so the expected beauty is $0.5 \cdot 0 + 0.5 \cdot 2 = 1$.

Difficulty: interview

Starter code:

Solutions:
# cook your dish here
t=int(input())
while(t>0):
 n=int(input())
 b=[int(x) for x in input().split()]
 p=[float(x) for x in input().split()]
 s=[0]*(10)
 yet=2
 mx=0
 for i in range(n):
  st=bin(b[i])
  rng=len(st)-2
  if(rng+2>yet):
   for ml in range(rng+2-yet):
    s.append(0)
  if(rng>mx):
   mx=rng
  for k in range(2,rng+2):
   if(st[k]=='1'):
    s[rng-k+1]=(s[rng-k+1]*(1-p[i]))+((1-s[rng-k+1])*(p[i]))
   # else:
   #     s[k-2]=(s[k-2]*1)
 # print(s)
 # print(mx)
 mult=1
 ans=0
 for i in range(0,mx):
  ans+=mult*s[i]
  mult=mult*2
 print("%.16f" % ans)
 t-=1

# cook your dish here
t=int(input())
while t:
 x=0
 n=int(input())
 b=list(map(int,input().strip().split()))
 p=list(map(float,input().strip().split()))
 for i in range(30):
  pb=0.0
  for j in range(n):
   if b[j]&(1<<i):
    pb=pb*(1-p[j])+(1-pb)*p[j]
  x+=(1<<i)*pb
 print(x)
 t-=1

for _ in range(int(input())):
 n = int(input())
 B = [int(x) for x in input().split()]
 P = [float(x) for x in input().split()]
 tl = [0]*30
 for b,p in zip(B,P):
  bs = bin(b)[2:][::-1]
  for i in range(len(bs)):
   if bs[i]=='1':
    tl[29-i] = (1-tl[29-i])*p + (1-p)*tl[29-i]
 ans = 0
 for i in range(29,-1,-1):
  ans += (2**(29-i))*tl[i]
 print(ans)

# cook your dish here
for _ in range(int(input())):
 n = int(input())
 xl = [int(x) for x in input().split()]
 pl = [float(x) for x in input().split()]
 tl = [0]*30
 for x,p in zip(xl,pl):
  bs = bin(x)[2:][::-1]
  for i in range(len(bs)):
   if bs[i]=='1':
    tl[i] = (1-tl[i])*p + (1-p)*tl[i]
 ans = 0
 for i in range(30):
  ans += (2**i)*tl[i]
 print(ans)

for _ in range(int(input())):
 n=int(input())
 xl=[int(x) for x in input().split()]
 pl=[float(x) for x in input().split()]
 tl=[0]*30
 for x,p in zip(xl,pl):
  bs=bin(x)[2:][::-1]
  for i in range(len(bs)):
   if bs[i]=='1':
    tl[i]=(1-tl[i])*p+(1-p)*tl[i]
 ans=0
 for i in range(30):
  ans+=(2**i)*tl[i]
 print(ans)

# cook your dish here
k = 30 
for _ in range(int(input())):
 n = int(input())
 l1 = list(map(int, input().split()))
 l2 = list(map(float, input().split()))
 ans = 0
 for i in range(k):
  p = 0
  for j in range(n):
   if(l1[j] & (1<<i)):
    p = p*(1-l2[j])+(1-p)*l2[j]
  ans += p*(1<<i)
 
 print("%.15f"%ans)

from bisect import bisect_right as br
from bisect import bisect_left as bl
from collections import *
from itertools import *
import functools
import sys
from math import *
from decimal import *
from copy import *
getcontext().prec = 30
MAX = sys.maxsize
MAXN = 10**6+10
MOD = 10**9+7
def isprime(n):
 n = abs(int(n))
 if n < 2:
  return False
 if n == 2: 
  return True 
 if not n & 1: 
  return False
 for x in range(3, int(n**0.5) + 1, 2):
  if n % x == 0:
   return False
 return True

def mhd(a,b):
 return abs(a[0]-b[0])+abs(b[1]-a[1])

def numIN(x = " "):
 return(map(int,sys.stdin.readline().strip().split(x)))

def charIN(x= ' '):
 return(sys.stdin.readline().strip().split(x))

def arrIN():
 return list(numIN())

def dis(x,y):
 a = y[0]-x[0]
 b = x[1]-y[1]
 return (a*a+b*b)**0.5

def lgcd(a):
 g = a[0]
 for i in range(1,len(a)):
  g = math.gcd(g,a[i])
 return g

def ms(a):
 msf = -MAX
 meh = 0
 st = en = be = 0
 for i in range(len(a)):
  meh+=a[i]
  if msf<meh:
   msf = meh
   st = be
   en = i
  if meh<0:
   meh = 0
   be = i+1
 return msf,st,en

def flush():
 return sys.stdout.flush()

'''*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*    '''

for _ in range(int(input())):
 n = int(input())
 a = arrIN()
 p = list(map(float,input().split()))
 dp = [0]*32
 for i in range(32):
  for j in range(n):
   if ((a[j]) & (1<<i)):
    dp[i] = (1-p[j])*dp[i]+(1-dp[i])*p[j]
 ans = 0
 for i in range(32):
  ans+=dp[i]*(1<<i)
 print(ans)

T=int(input())
for i in range(0,T):
 N=int(input())
 b=[int(x) for x in input().split()]
 p=[float(x) for x in input().split()]
 arr=[0]*32
 for j in range(0,len(b)):
  st=bin(b[j])
  st=st[2:]
  #print(st)
  for k in range(1,len(st)+1):
   if(st[-k]=='1'):
    arr[k-1]=((1-arr[k-1])*p[j])+((1-p[j])*arr[k-1])
  #for k in range(len(st)-1,-1,-1):
   #if(st[k]=='1'):
    #arr[N-k-1]=(arr[N-k-1]*(1-p[j]))+((1-arr[N-k-1])*p[j])
    #print(N-k,arr)
 #print(arr)

 exp=0
 xr=1
 for j in range(0,len(arr)):
  exp=exp+(xr*arr[j])
  xr=xr*2

 print(exp)




# cook your dish here
l=[1]
for k in range(31):
 l.append(l[-1]*2)
def convert(s):
 while len(s)!=32:
  s='0'+s
 ans=""
 for i in s:
  ans=i+ans
 return ans
def main():
 for _ in range(int(input())):
  n=int(input())
  val=list(map(int,input().split()))
  p=list(map(float,input().split()))
  res=0
  for i in range(32):
   x=0
   for j in range(n):
    if val[j] & (1<<i):
     x=(p[j]*(1-x))+(1-p[j])*(x)
   res+=(l[i]*x)
  print("%.6f"%res)
def __starting_point():
 main()
     

__starting_point()

for _ in range(int(input())):
 n=int(input())
 a=list(map(int,input().split()))
 b=list(map(float,input().split()))
 ans=0
 for i in range(30):
  temp=0
  for j in range(n):
   if (a[j]&(1<<i)):
    temp=temp*(1-b[j])+(1-temp)*b[j]
  ans+=temp*(1<<i)
 print(ans)


t = int(input())
while(t>0 ):
 n= int(input())
 #b = [0]*n;
 B=list(map(int,input().strip().split(' ')))
 P=list(map(float,input().strip().split(' ')))
 l = [0]*32
 ans = 0 
 cur_bit = 1
 for i in range(0,31):
  # print(cur_bit,end =" ")
  cur_prob = 0.0
  for j in range(0,len(B)):
   if(cur_bit&B[j]):
    cur_prob = cur_prob*(1-P[j]) + (1-cur_prob)*P[j]
  cur_bit = cur_bit << 1
  # print(cur_prob)
  ans = ans + cur_prob* (2**i)

 print(ans)


 t-=1;

t=int(input())
while(t>0):
 n=int(input())
 b=[int(x) for x in input().split()]
 p=[float(x) for x in input().split()]
 s=[0]*(10)
 yet=2
 mx=0
 for i in range(n):
  st=bin(b[i])
  rng=len(st)-2
  if(rng+2>yet):
   for ml in range(rng+2-yet):
    s.append(0)
  if(rng>mx):
   mx=rng
  for k in range(2,rng+2):
   if(st[k]=='1'):
    s[rng-k+1]=(s[rng-k+1]*(1-p[i]))+((1-s[rng-k+1])*(p[i]))
   # else:
   #     s[k-2]=(s[k-2]*1)
 # print(s)
 # print(mx)
 mult=1
 ans=0
 for i in range(0,mx):
  ans+=mult*s[i]
  mult=mult*2
 print("%.16f" % ans)
 t-=1

for _ in range(int(input())):
 n = int(input())
 xl = [int(x) for x in input().split()]
 pl = [float(x) for x in input().split()]
 tl = [0]*30
 for x,p in zip(xl,pl):
  bs = bin(x)[2:][::-1]
  for i in range(len(bs)):
   if bs[i]=='1':
    tl[i] = (1-tl[i])*p + (1-p)*tl[i]
 ans = 0
 for i in range(30):
  ans += (2**i)*tl[i]
 print(ans)