Dark Nights
Little Petya loves his job as a night shift guard, where he is responsible for protecting N towers. Each tower is equipped with a light bulb that can either be functioning or broken, and each tower contains a certain amount of treasure. Petya is aware that thieves might attempt to steal the treasures each night. However, these thieves are afraid of the dark and will only target towers with a working light bulb. Every night, some bulbs are repaired while others break. Specifically, according to the Unknown Universal Law, the state of bulb P[i] will match the state of bulb i from the previous night. Additionally, all P[i] values are unique.
Petya wants to determine the maximum amount of treasure that could be stolen on the first night, the second night, and so on, up to the M-th night. The thieves are hypothetical, so we assume no treasure is actually stolen at the start of each night. During any given night, thieves can steal from any tower with a working light bulb, and they can target multiple towers in one night.
Input
The first line of input contains the number of towers N (1 ≤ N ≤ 10^5). The second line contains N distinct integers ranging from 1 to N. The i-th number on this line is P[i]. The third line provides N integers, each between zero and 10^6, representing the amount of treasure in the i-th tower. The fourth line is a string of N characters, where each character is either 0 or 1. The i-th character is 0 if the bulb in the i-th tower is broken and 1 if it is working. The fifth line contains an integer M (1 ≤ M ≤ 10^5), which is the number of nights Petya wants to evaluate.
Output
The output should consist of exactly M lines. The i-th line should display the amount of treasure that could be hypothetically stolen on the i-th night, calculated modulo 10^9+7.