Ellen is a student at RHHS who is trying to navigate her way through the school to get to her classes. She knows that most halls are going to be blocked off by large groups of aimless students, so she has devised a map of the school which only includes hallways she knows will be open. In particular, the school can be represented as a collection of classrooms numbered to with hallways between them. It is guaranteed that these hallways will never form a loop.
Because Ellen is travelling around the school a lot, she wants to know how far it is between various different locations in the school, so she can plan how long it will take to walk between them.
To help her with this, you will be given queries; for each one you must determine the distance between the two given classrooms.
The first line will contain , the number of classrooms.
The next lines will contain three space-separated integers, , , , , indicating that there is a hallway between classrooms and with length .
The next line will contain , the number of queries to be answered.
The next lines will contain two space-separated integers, and , representing a query that asks the distance between classrooms and .
For test cases worth 20 of 100 points, and .
For test cases worth an additional 20 points, .
For each query, output a single integer on its own line which is the distance between the two classrooms in the query.
5 0 1 3 0 3 2 0 4 7 1 2 5 4 2 0 1 4 3 1 3 4
8 10 5 9