Neurotic Network

No attempts yetTime limit1sMemory limit256 MB

Problem

In this problem a neural net is a rooted tree with a weight on every edge. Signals cascade from the leaf nodes toward the root: each node computes an output value from its upstream neighbours and passes that value on to its single downstream neighbour. The output value of a node is the sum, over all of its upstream neighbours, of that neighbour's output value multiplied by the weight of the edge running from the neighbour into the node. A node with no upstream neighbour is a leaf, and a leaf always has 1 as its output. Every neural net in this problem has exactly one final output node, the root node.

A neural net sometimes goes haywire and becomes what is more commonly known as a neurotic network. Consider this your chance to start a second career in psychiatry. Someone has just walked in with a neurotic network in their head. If the output of their neural net is an even number, the person freaks out and sets fire to a kitten. Knowing ahead of time whether a given person is safe therefore matters. If the person is safe, print their neural output modulo 1,000,000,007. If you would not trust the person around kittens who are not wrapped in fire retardant, print the string FREAK OUT without the quotes.

Input

The first line contains TT, the number of test cases. Each test case begins with a line holding the integer NN, the number of nodes in the tree. The next line contains N1N - 1 integers a1,a2,,aN1a_1, a_2, \dots, a_{N-1}, where aia_i is the downstream neighbour of the node with ID ii. The line after that contains N1N - 1 integers w1,w2,,wN1w_1, w_2, \dots, w_{N-1}, where wiw_i is the weight of the neural connection going out from the node with ID ii. The node with ID 0 is always the output node.

  • 0<T500 < T \le 50
  • 0<N100000 < N \le 10000
  • 0<wi100 < w_i \le 10
  • 0ai<N0 \le a_i < N
  • The given graph is always a tree.

When N=1N = 1 both integer lines are empty. This is an I/O heavy problem, so read the input with a buffered reader.

Output

Print one line per test case. If the final value of the neural net's output node is even, print FREAK OUT without the quotes. Otherwise print that final value modulo 1,000,000,007.