#P3292. [SCOI2016] 幸运数字

[SCOI2016] 幸运数字

Description

Country A has nn cities connected by n1n - 1 roads, so that any two cities are mutually reachable and the path between them is unique. Each city has a lucky number, which stands at the very center of the city in the form of a monument, serving as the symbol of the city.

Some travelers want to tour Country A. A traveler plans to land in city xx, travel along the unique path from city xx to city yy, and finally depart from city yy. When passing through each city, the traveler has a chance to take a photo with that city's lucky number, thereby keeping this luck. However, luck cannot be simply stacked, and the traveler knows this well. They believe that luck is kept on them via xor.

For example, if a traveler takes 33 photos with lucky values 5,7,115, 7, 11, then the lucky value finally kept is 5xor7xor11=95 \operatorname{xor} 7 \operatorname{xor} 11 = 9.

Some smart travelers have found that by selectively taking photos, they can obtain a larger lucky value. For instance, among the three lucky values above, if they only choose 55 and 1111, the lucky value kept is 1414. Now, some travelers have come to you for help. Given their itineraries, please compute the maximum lucky value they can keep.

Input Format

The first line contains 22 positive integers n,qn, q, denoting the number of cities and the number of travelers.

The second line contains nn non-negative integers, where the ii-th integer GiG_i denotes the lucky value of city ii.

The next n1n - 1 lines each contain two positive integers x,yx, y, indicating that there is a road between city xx and city yy.

The next qq lines each contain two positive integers x,yx, y, indicating that this traveler’s plan is to go from city xx to city yy.

Output Format

Output qq lines. Each line contains one non-negative integer, the maximum lucky value that this traveler can keep.

4 2
11 5 7 9
1 2
1 3
1 4
2 3
1 4
14 
11

Hint

For 100%100\% of the testdata, it is guaranteed that n2×104n \leq 2 \times 10^4, q2×105q \leq 2 \times 10^5, Gi260G_i \leq 2^{60}.

Translated by ChatGPT 5