Back and Forth
시간 제한1초메모리 제한256 MB
역마다 표를 사면 그 역을 몇 번이든 지날 수 있을 때, s에서 t로 갔다가 s로 돌아오는 왕복이 가능하도록 사야 하는 표 가격의 최솟값을 구한다.
문제
There are stations and directed roads between them.
One day, Chiaki is going from the -th station to the -th station, then back to the -th station. Doing so, he needs to buy tickets for stations he passes. The price the tickets for the -th station is . If Chiaki buys a ticket for the -th station, he can passes the station as many times as he wants. Find the minimum price of tickets to buy.
입력
There are multiple test cases. The first line of the input contains an integer () indicating the number of test cases. For each test case:
The first line of each test case contains four integers , , and (, , ). The second line contains integers (). The -th of the following lines contains two integers and , which denote a road from the station to the -th station ().
The sum of all does not exceed .
출력
For each test case, output an integer denoting the answer. Print for no solution.