AND gates and OR gates are basic components used in building digital circuits. Both gates have two input lines and one output line. The output of an AND gate is 1 if both inputs are 1, otherwise the output is 0. The output of an OR gate is 1 if at least one input is 1, otherwise the output is 0.

You are given a digital circuit composed of only AND and OR gates where one node (gate or input) is specially designated as the output. Furthermore, for any gate G and any input node I, at most one of the inputs to G depends on the value of node I.

Now consider the following random experiment. Fix some probability p in [0,1] and set each input bit to 1 independently at random with probability p (and to 0 with probability 1-p). The output is then 1 with some probability that depends on p. You wonder what value of p causes the circuit to output a 1 with probability 1/2.

-----Input-----

The first line indicates the number of test cases to follow (about 100).

Each test case begins with a single line containing a single integer n with 1 ≤ n ≤ 100 indicating the number of nodes (inputs and gates) in the circuit. Following this, n lines follow where the i'th line describes the i'th node. If the node is an input, the line simply consists of the integer 0. Otherwise, if the node is an OR gate then the line begins with a 1 and if the node is an AND gate then the line begins with a 2. In either case, two more integers a,b follow, both less than i, which indicate that the outputs from both a and b are used as the two input to gate i.

As stated before, the circuit will be such that no gate has both of its inputs depending on the value of a common input node.

Test cases are separated by a blank line including a blank line preceding the first test case.


-----Output-----

For each test case you are to output a single line containing the value p for which the output of node n is 1 with probability exactly 1/2 if the inputs are independently and randomly set to value 1 with probability p. The value p should be printed with exactly 5 digits after the decimal.


-----Example-----
Input:

4

1
0

3
0
0
1 1 2

3
0
0
2 1 2

5
0
0
0
2 1 2
1 3 4

Output:

0.50000
0.29289
0.70711
0.40303

-----Temporary Stuff-----

A horizontal rule follows.

***

Here's a definition list (with `definitionLists` option):

apples
: Good for making applesauce.
oranges
: Citrus!
tomatoes
: There's no "e" in tomatoe.

#PRACTICE
- This must be done
[http:codechef.com/users/dpraveen](http:codechef.com/users/dpraveen)

(0.8944272−0.44721360.4472136−0.8944272)(10005)(0.89442720.4472136−0.4472136−0.8944272)(10005)
\left(\begin{array}{cc} 
0.8944272 & 0.4472136\\
-0.4472136 & -0.8944272
\end{array}\right)
\left(\begin{array}{cc} 
10 & 0\\ 
0 & 5
\end{array}\right)

Difficulty: UNKNOWN_DIFFICULTY

Starter code:

Solutions:
class node:

	def __init__(self, a, b=0, c=0):
		self.val = a
		self.a = b
		self.b = c
arr = []

def finder(node, val):
	if arr[node].val == 0:
		return val
	else:
		a = finder(arr[node].a, val)
		b = finder(arr[node].b, val)
		if arr[node].val == 1:
			return a + b - a * b
		else:
			return a * b
t = int(input())
while t > 0:
	x = input()
	n = int(input())
	arr.append(node(0))
	for i in range(0, n):
		vals = input().split()
		sz = len(vals)
		for i in range(0, sz):
			vals[i] = int(vals[i])
		if vals[0] == 0:
			next = node(0)
			arr.append(next)
		else:
			next = node(vals[0], vals[1], vals[2])
			arr.append(next)
	lower = 0.0
	higher = 1.0
	eps = 1e-09
	while higher - lower > eps:
		mid = (higher + lower) / 2.0
		if finder(n, mid) > 0.5:
			higher = mid
		else:
			lower = mid
	print('%.5f' % higher)
	arr = []
	t -= 1