You are given an undirected tree with tree_nodes nodes, rooted at node 0. Node i stores a lowercase character arr[i]. For each query node q, consider every node v on the path from q up to the root, including q itself. For each such v, look at the characters on the path segment from q up to v, inclusive. Count how many of those path segments can be rearranged to form a palindrome. Return an array of answers in the same order as queries. A multiset of characters can be rearranged into a palindrome if at most one character has odd frequency.
Examples
Input: (1, ['a'], [], [0])
Expected Output: [1]
Explanation: The only path segment is ['a'], which is already a palindrome.
Input: (4, ['z', 'a', 'a', 'a'], [(0, 1), (0, 2), (1, 3)], [3])
Expected Output: [3]
Explanation: For query node 3, the segments 3->3, 3->1, and 3->0 all have at most one odd character count.
Input: (3, ['a', 'b', 'a'], [(0, 1), (1, 2)], [2, 1, 0])
Expected Output: [2, 1, 1]
Explanation: For node 2, segments 'a' and 'aba' work. For node 1, only 'b' works. For node 0, only 'a' works.
Input: (5, ['a', 'b', 'b', 'a', 'c'], [(0, 1), (0, 2), (1, 3), (1, 4)], [3, 4, 2])
Expected Output: [2, 1, 1]
Explanation: Query 3 has valid segments 'a' and 'aba'. Query 4 has only 'c'. Query 2 has only 'b'.
Input: (4, ['a', 'a', 'b', 'b'], [(0, 1), (1, 2), (2, 3)], [3, 3])
Expected Output: [4, 4]
Explanation: All four ancestor segments for node 3 can be rearranged into palindromes, and the query is repeated.