ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules

Ural Regional School Programming Contest 2014

About     Problems     Submit solution     Judge status     Standings
Contest is over

G. Awesome Backup System

Time limit: 2.0 second
Memory limit: 64 MB
It is known that all people can be divided into two groups: those who have never lost important data and those who regularly perform data backups. Kirill is on his way from the first group to the second after the incident with tests described in the problem “Another Dress Rehearsal”. Not satisfied with the existing data backup solutions for various reasons, he decided to design his own backup system. He chose a simple but proud name for it: the “Awesome Backup System,” ABS for short. Since errors in such an important system are absolutely unacceptable, Kirill asks you to test the beta version of his product.
The ABS is organized as follows: let there be n computers in a local network. The computers are numbered with integers from 1 to n. Some pairs of computers are connected by cables. For economy, the network doesn’t have unnecessary cables, which means that there is a unique cable path between any two computers. Initially there are ai bytes of information written on the i-th computer. The ABS can process two types of requests:
  1. Copy all the information from computer v to all adjacent computers (i.e., to all computers directly connected to it by a cable) If computer v had xv bytes of information, then, after copying, all adjacent computers will have xv bytes of information more, while computer v will still have xv bytes of information.
  2. Output the current amount of information on computer v. Since this amount can grow very quickly, output the remainder of its division by the number 109 + 7.
For testing the ABS, you are asked to write a program for a quick processing of such requests.

Input

The first line contains the number n of computers in the network (1 ≤ n ≤ 105). In the second line you are given integers a1, …, an, which are the amounts of information (in bytes) on the computers at the initial time (0 ≤ ai ≤ 109). Each of the following n − 1 lines contains integers x and y (1 ≤ x, yn; xy), which mean that the computers with numbers x and y are connected by a cable. It is guaranteed that the network is connected.
The next line contains the number m of requests to the system (1 ≤ m ≤ 105). In the following m lines you are given the requests in the order of their execution. Each request is a pair of integers t and v (1 ≤ t ≤ 2 and 1 ≤ vn), where t specifies the type of the request and v is the number of the computer to which the request is applied.

Output

For each request of the second type, output in a separate line the remainder of the division of the answer by the number 109 + 7.

Samples

inputoutput
4
1 1 1 1
1 2
1 3
2 4
9
2 1
2 2
2 3
2 4
1 1
2 1
2 2
2 3
2 4
1
1
1
1
1
2
2
1
2
1 1
1 2
14
2 2
2 1
1 1
2 2
1 2
2 1
1 1
2 2
1 2
2 1
1 1
2 2
1 2
2 1
1
1
2
3
5
8
13
21
Problem Author: Nikita Sivukhin
Problem Source: Ural Regional School Programming Contest 2014
To submit the solution for this problem go to the Problem set: 2030. Awesome Backup System