For each query (S, E), find the minimum possible maximum value of C[a]*C[b] over calls made while the two travelers swap cities.
Hard8GraphShortest pathGreedyNo attempts yetTime limit2sMemory limit256 MBIn the land of Seokhwan there are two people named Seunghyun. To tell them apart, call one of them Seunghyun 13 and the other Seunghyun 16. Neither knew the other existed until a news story told them so a while ago. Finding it strange that someone shared their name, they tracked down each other's number and started talking often.
One day each of them got curious about the city the other lives in. Describing a city over the phone wore them out, so they decided to travel to each other's city instead.
Seokhwan has N cities numbered 1 through N, and M roads run between them. One road joins two different cities and can be walked in both directions. Starting from any city, you can follow roads and reach every other city.
Seunghyun 13 is in city S and Seunghyun 16 lives in city E. To explain the way to their own city, they keep the phone call up and travel like this.
A call needs a phone that can put out at least a certain radio signal power. Each city i has a positive integer Ci that says how well radio signals spread there, and a call between city a and city b needs a phone that can put out at least Ca×Cb. Strange as it is, the rule still applies when both of them are inside the same city.
Before the trip starts, the two Seunghyuns each buy one identical phone and use only that phone until the trip ends. A phone costs in proportion to the output it can put out, so the way they travel changes how expensive the phone has to be. Given S and E, find the smallest phone output that lets them finish the trip safely.
The input is a single test case.
The first line has the number of cities N (2≤N≤500) and the number of roads M (1≤M≤3000).
The second line has N integers. The i-th integer is Ci (1≤Ci≤40000), the radio signal constant of city i.
Each of the next M lines has two integers a and b (1≤a,b≤N, a=b) separated by a space, meaning a road joins city a and city b.
The next line has the number of questions Q (1≤Q≤(2N)). Each of the next Q lines has two integers S and E (1≤S,E≤N, S=E) separated by a space, meaning Seunghyun 13 starts in city S and Seunghyun 16 starts in city E.
Print the answers to the questions on Q lines, in the given order. On the i-th line print the smallest phone output that finishes the trip safely for the i-th question.