You are given a rooted tree with \(n\) vertices. Here, \(A\) and \(B\) are playing with the tree. In each turn (starting with \(A\)), each player can select a vertex \(v\) that contains no parent and delete a path with at least two vertices starting from \(v\).
A player loses if he or she cannot make the turn in the game. For each test case, determine who will win.
Input format
- The first line contains \(t\) denoting the number of test cases.
- The first line of each test case contains \(n\) denoting the number of tree's vertices.
- Next \(n-1\) lines of each test case contain \(p_{i}\) that means the \((i+1)^{th}\) vertex's parent is \(p_{i} \).
Output format
For each test case, print \(A\) if \(A\) wins, otherwise print \(B\).
Constraints
\(1 \leq n \leq 5 \times 10^4\)
\(1 \le p_{i} \le i\)
\(1 \le t \le 10\)
In the first test, player B will always have a path of two vertices after A's move that will finish the game, so B is the winner.
In the second test, after any player A's choice for the path, the tree will become a set of vertices without any edge, so A is the winner.
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor
Login to unlock the editorial
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor