Autobus
시간 제한1초메모리 제한512 MB
가중치가 있는 방향 그래프에서 최대 k개의 간선을 사용해 두 도시 사이를 이동하는 최단 시간을 묻는 질의에 답한다.
문제
In a country there are cities. The cities are connected by bus routes, where the -th route starts in city , ends in city and takes minutes.
Ema loves to travel, but doesn’t like transferring between buses. On her trip she wants to use at most different bus routes.
Help her answer questions of the form ‘What is the shortest travel time to get from city to city (using at most different bus routes)?’.
입력
The first line contains two positive integers and (, ), the number of cities and the number of bus routes.
The -th of the next lines contains positive integers , and (, ), the terminal cities and the travel time of the -th bus route.
The next line contains two positive integers and (, ), the maximum number of used routes and the number of queries.
The -th of the next lines contains positive integers and (), the cities from the -th query.
출력
Print lines. In the -th line print the shortest travel time from the -th query, or -1 if there is no trip that satisfies the requirements.
힌트
Clarification of the examples:

The answer to the first query from each example is marked on the graph.