Under construction

Still being built. Things may change

Candy Delivery

Time limit3sMemory limit1024 MB

Summary
On a tree of N candy stores with five candy types, decide for each friend in order whether Yunjae, choosing his start freely, can walk a shortest path to the friend and pass a store selling the wanted candy.
Level

Hard8 of 10

Topics
Tree, DFS, Prefix sum, Linked list
Solved
No attempts yet

Problem

The village where Yunjae lives has NN candy stores. The stores are numbered from 11 to NN. Each store sells only one of five kinds of candy. There is also a road network of N−1N-1 roads connecting the candy stores. Every road takes 11 unit of time to traverse, and using the roads one can travel from any candy store to every other candy store.

Today Yunjae plans to meet MM friends one at a time, in order. On the way to meet each friend, he must buy the kind of candy that friend likes. If he fails, the friend gets angry and leaves.

To meet his friends quickly, Yunjae sets off for the next friend immediately after meeting one friend. To save as much time as possible, he always travels along a shortest path, and along the way he stops at candy stores he passes and buys candy there. He may also buy candy at a store located where the friend is. However, his pockets are small, so he can carry only one candy at a time. That is, while on the way to meet some friend A, he cannot buy a candy for another friend B in advance.

To find out in advance which friends will leave him, Yunjae wants to know whether he can buy candy for each friend. Yunjae may choose his starting location freely. Write a program that helps Yunjae determine, for each friend, whether he can buy the kind of candy that friend likes.

Input

The first line gives an integer NN, the number of candy stores. (1≤N≤100 0001 \leq N \leq 100\ 000)

The second line gives NN integers separated by spaces, indicating the kind of candy sold at each candy store. A candy kind is a positive integer between 11 and 55.

From the third line, N−1N-1 lines give road information as pairs u,vu, v. This means there is a bidirectional road connecting candy store uu and candy store vv. (1≤u,v≤N1 \leq u, v \leq N, u≠vu \neq v)

The next line gives an integer MM, the number of friends. (1≤M≤100 0001 \leq M \leq 100\ 000)

The next MM lines give, in order of earliest appointment time, the number of the store where each friend stands and the kind of candy that friend likes. Several friends may stand in front of the same store.

Output

In order of earliest appointment time, print PLAY on its own line if Yunjae can buy the kind of candy that friend likes, and CRY otherwise.

Examples2

  1. Example 1

    Input
    5
    1 2 3 4 5
    1 2
    1 3
    2 4
    2 5
    4
    3 5
    4 2
    5 3
    3 4
    
    Expected output
    PLAY
    PLAY
    CRY
    CRY
    
  2. Example 2

    Input
    5
    1 2 3 4 5
    1 2
    1 3
    2 4
    2 5
    3
    1 2
    1 1
    4 3
    
    Expected output
    PLAY
    PLAY
    CRY