there root tree consist n node number 0 n 1 each node number denote unique genetic value ie genetic value node x x the genetic difference genetic value define bitwisexor value you give integer array parent parentsi parent node if node x root tree parentsx 1you give array query queriesi nodei vali for query find maximum genetic difference vali pi pi genetic value node path nodei root include nodei root more formally want maximize vali XOR piReturn array ans ansi answer ith query Example 1input parent 1011 query 023225output 237explanation the query process follow 02 the node maximum genetic difference 0 difference 2 xor 0 2 32 the node maximum genetic difference 1 difference 2 xor 1 3 25 the node maximum genetic difference 2 difference 5 xor 2 7example 2input parent 37120702 query 4611505output 6147explanation the query process follow 46 the node maximum genetic difference 0 difference 6 xor 0 6 115 the node maximum genetic difference 1 difference 15 XOR 1 14 05 the node maximum genetic difference 2 difference 5 XOR 2 7 constraints2 parentslength 1050 parentsi parentslength 1 node rootparentsroot 11 querieslength 3 1040 nodei parentslength 10 vali 2 105