There are *N* cities in a country, and there is one and only one simple path between each pair of cities. A merchant has chosen some paths and wants to earn as much money as possible in each path. When he move along a path, he can choose one city to buy some goods and sell them in a city after it. The goods in all cities are the same but the prices are different. Now your task is to calculate the maximum possible profit on each path.

The first line contains *N*, the number of cities.
Each of the next *N* lines contains *w*_{i} the goods' price in each city.
Each of the next *N-1* lines contains labels of two cities, describing a road between the two cities.
The next line contains *Q*, the number of paths.
Each of the next *Q* lines contains labels of two cities, describing a path. The cities are numbered from 1 to *N*. 1 ≤ *N*, *w*_{i}, *Q* ≤ 50000

提交代码