

You are given an arbitrary binary tree consisting of 'N' nodes numbered from 1 to 'N', and each node is associated with some positive integer value. Your task is to find the average of all the levels in the given tree, i.e you have to find the average of all the node values present on the level, for each level.
Two nodes of a tree are said to be at the same level ‘K’ if both of them are at equal distance( 'K' ) from the 'ROOT' node. The 'ROOT' node is said to be at level 0.
Note :
1. Two nodes may have the same value associated with it.
2. Average of any level is computed as the sum of the values of all the nodes at that level divided by the number of nodes at that level.
3. You will be given the 'ROOT' node of the binary tree.
4. You need to print the floor value for each average. For example, if the average of node values at some level is 3.5 then you have to print 3.
The first line of the input contains a single integer 'T', representing the number of test cases.
The first line of each test case contains a single integer 'N' denoting the number of nodes in the tree.
The second line contains the values of the nodes of the tree in the level order form ( -1 for NULL node)
Example :
Consider the binary tree

The input of the tree depicted in the image above will be like :
1
2 3
4 -1 5 6
-1 7 -1 -1 -1 -1
-1 -1
Explanation :
Level 1 :
The root node of the tree is 1
Level 2 :
Left child of 1 = 2
Right child of 1 = 3
Level 3 :
Left child of 2 = 4
Right child of 2 = null (-1)
Left child of 3 = 5
Right child of 3 = 6
Level 4 :
Left child of 4 = null (-1)
Right child of 4 = 7
Left child of 5 = null (-1)
Right child of 5 = null (-1)
Left child of 6 = null (-1)
Right child of 6 = null (-1)
Level 5 :
Left child of 7 = null (-1)
Right child of 7 = null (-1)
The first non-null node (of the previous level) is treated as the parent of the first two nodes of the current level. The second non-null node (of the previous level) is treated as the parent node for the next two nodes of the current level and so on.
The input ends when all nodes at the last level are null (-1).
Output Format :
For each test case, print 'X' space-separated values where 'X' is the number of levels in the given binary tree, where the 'i'th integer will denote the average of node values at the 'ith level.
Note :
You don't need to print anything, it has already been taken care of. Just implement the given function.
1 <= T <= 10^2
1 <= N <= 10^4
1 <= data <= 10^9
Time Limit : 1 sec
1
3
1 2 3 -1 -1 -1 -1
1 2
This is the tree as described in the input here l0 denotes level-0 and l1 denotes level-1. Now the average of nodes at level 0 is (1/1), which is 1. And the average at level 1 is ((2+3)/2) which is 2.50
1
4
5 6 7 8 -1 -1 -1 -1 -1
5 6 8
This is the tree as described in the input here l0 denotes level-0 and l1 denotes level-1 and l2 denotes level-2. Now the average of nodes at level 0 is (5/1), which is 5. And the average at level 1 is ((6+7)/2) which is 6.50, and the average at level-2 is (8/1) which is 8.
Do the level - order traversal.
The fact that we need to find the average at each level clearly indicates the need to do a level order traversal of the given tree. So we will run a BFS using a FIFO queue and compute the average at each level.
Here is the algorithm :
Example :
O(N), where ‘N’ is the number of nodes in the tree.
We traverse all the nodes of the binary tree to find the average. Hence, the overall time complexity will be O(N).
O(N), where ‘N’ is the number of nodes in the tree.
We use a queue to store nodes present at a level which in the worst case can be equal to ‘N’ / 2. In the case of a complete binary tree number of nodes present at each level is 2^'L' (where ‘L’ is the current level). If the tree has 2 levels then the last level will have 2^2 = 4 nodes and the total nodes will be 7 i.e. nodes at the last level is equal to ‘N’/2. Therefore, the overall space complexity will be O(N).