As you all know, AI use is on the rise. As our friend Gigel dislikes this, he came up with a plan of sabotaging the growth of AI.
An AI brain works in intricate ways. First lets consider an infinite grid where there are neurons placed. We know for each neuron its position in the grid and its color, given as a tuple . An AI Thought is described by:
- The length of the neural sequence , meaning that our thought is created by a list of neurons.
- The colors we want to use for our list of neurons, . This means that the neuron in our thought list should have the color . As an important observation, we are allowed to use the same neuron multiple times in our list.
- The time we need to generate this thought is , where is the Manhattan distance between points (neurons) and in the grid().
Now, depending on how we choose the neurons, the time needed for generating a thought can differ. As Gigel hates AI, he wants to prove the world how inefficient it is, so he asks for your help. In order to do this, you need to compute for thoughts the maximum possible amount of time for generating each thought.
Input data
The first line of the input contains , the number of neurons ().
The next lines of the input contain the neurons we can use for our thoughts (), ().
The next line contains , the number of thoughts we need to analyze ().
The next lines contain , the number of points in the thought ( and then inteegers representing the colors we need to use for the neurons in this thought (.
It is guaranteed that the sum of values is at most and each color used is present in at least one neuron from the set of neurons.
Output data
The output will contain lines, on each line we have the answer for the question.
Example
stdin
8
1 1 3
-1 4 2
3 2 4
4 1 1
-2 -3 4
-1 2 1
2 2 3
3 0 2
2
5
1 2 1 2 4
3
3 1 2
stdout
32
11
Explanation
For the first thought, we can use the fourth, the second, the fourth, the second and the fifth neuron, in this order.
For the second thought, we can use the first, the fourth and the second neuron, in this order.