A merchant is making a business travel plan. His trip begins at a starting town and ends at a destination town
, visiting each town from
to
(inclusive) exactly once. The merchant starts the trip on a Monday. It takes him exactly one day to travel between adjacent towns and every day he travels to the next town on the path to the destination. He may buy exactly one goodie at a town along the trip and sell that goodie at a town he visits later. He can only buy once and sell once. The merchant would like to know the maximum possible profit of
travel plans with different choices of town
and town
.
The first line of the input has a single integer. The next
lines each have two integers. The
-th line has
and
. The next line has a single integer
. The following
lines each give a pair of integers
and
, representing one travel plan from town
to town
. If
the merchant travels west to east, otherwise he travels east to west.
For each travel plan, output the maximum profit the merchant can make on a single line. If the merchant cannot make any profit, output.