You are given a tree with nodes labelled from to , the root of which is the node . Each node has a given value .
We define as the number of edges in the shortest path from the node to the node , and define a multiset as . Note that here .
We define the score of any arbitrary set as the sum of squares of XORs of any two numbers. For example, the score of the set should be
where denotes the bitwise exclusive-or.
Now you are given the parameter . For each node you need to compute the score of .