#P9824. Teyberrs
Teyberrs
Teyberrs
Problem Description
Teyberrs is a paradise for birds to live in. Assume you are a bird in Teyberrs, you are now flying somewhere like the game ''Flappy Bird''. You start flying at , and every time when you are at (), you must fly to either with cost or with cost . Like the map in ''Flappy Bird'', you can not hit obstacles at where or . You will be given queries. In each query, you will be given two integers and . Assume your target is at , can you find the path with the minimum cost, or determine it is impossible?
Input
The first line contains a single integer (), the number of test cases. For each test case: The first line of the input contains three integers , and (, ), denoting the size of the map, the number of queries, and the start point. In the next lines, the -th line contains four integers , , and (, ). In the next lines, the -th line contains two integers and (), describing a target point. It is guaranteed that the sum of all is at most , and the sum of all is at most .
Output
For each query, print a single line containing an integer, denoting the minimum total cost. When it is impossible to reach the target, please print '''' instead.
Sample Input
1
3 9 2
1 2 1 3
3 1 2 3
4 3 1 2
1 1
1 2
1 3
2 1
2 2
2 3
3 1
3 2
3 3
Sample Output
1
-1
2
-1
2
-1
6
-1
-1
Source
2023“钉耙编程”中国大学生算法设计超级联赛(3)