Gahui and ILGAM lake
시간 제한1초메모리 제한1024 MB
고리 모양으로 배치된 4n개의 점 사이에 가중치 간선이 있고 네 점이 지하철역과 연결되어 있을 때, 각 질의 점에서 가장 가까운 역까지의 거리를 구한다.
문제
Gahui often visited Konkuk University. Every time Gahui visited Konkuk University, she was surprised to see the huge ILGAM lake. It is bigger than several universities, such as Seokyung university and Hanseong university.
The lake has 4n points arranged like a ring, each numbered from 1 to 4n in counter-clockwise order. Each pair of adjacent points are connected in both directions. In other words:
- If
1≤a<4n, pointais connected to pointa+1in both directions. - Point
1is connected to point4nin both directions.
Points n, 2n, 3n, and 4n are connected to 3 subway stations (Konkuk_Univ, Guui, Sejong_Univ) via roads. ILGAM lake is so big, the nearest station is different depending on the point. Gahui wants to know which subway station is the nearest to her current point. Please help Gahui.

[Picture 1] Roads and points when n = 2
입력
n is given in the first line.
In the next line, 4n numbers are given in the following format:
d1 d2 ... d4n
diis distance from pointito pointi+1when1≤i<4nd4nis distance from point4nto point1
And the information below is given on four lines.
dn,Konkuk_Univ dn,Guui dn,Sejong_Univ
d2n,Konkuk_Univ d2n,Guui d2n,Sejong_Univ
d3n,Konkuk_Univ d3n,Guui d3n,Sejong_Univ
d4n,Konkuk_Univ d4n,Guui d4n,Sejong_Univ
da,b is the distance between point a and station b.
In the next line, Q (number of questions) is given.
In the next Q lines, Q questions are given in the following format, one per line.
k- What is the distance to the nearest station from point
k?
- What is the distance to the nearest station from point
출력
Print the answers to the questions, one per line.
제한
1≤all distances in the problem≤1051≤n≤1051≤Q≤105