Shivam owns a gambling house, which has a special wheel called The Wheel of Fortune. 
This wheel is meant for giving free coins to people coming in the house. 

The wheel of fortune is a game of chance. It uses a spinning wheel with exactly N numbered pockets and a coin is placed in between every consecutive pocket. The wheel is spun in either of the two ways.
Before the wheel is turned, all the coins are restored and players bet on a number K.
Then a needle is made to point to any one of the pocket which has number K written on it.
Wheel is then spun till the needle encounters number K again and the player gets all the coins the needle has encountered.

Shivam being the owner of the gambling house, has the authority to place the needle on any of the K numbered pockets and also he could rotate the wheel in either of the two ways.
Shivam has to figure out a way to minimize number of coins that he has to spend on every given bet.
You are given a wheel having N elements and Q players. Each player bets on a number K from the wheel. For each player you have to print minimum number of coins Shivam has to spend.


-----Input-----
- The first line of the input contains an integer T denoting the number of test cases . The description of T testcases follow.

- The first line of each test case contains single integer N .

- The second line of each test case contains N space seperated integers denoting the numbers on the wheel.

- The third line of each test case contains a single integer Q denoting the number of players.
- Then, Q lines follow a single integer K from the N numbers of the wheel 

-----Output-----
For each player, output the minimum number of coins Shivam has to spend.


-----Constraints-----

- 1 ≤ T ≤ 10
- 1 ≤ N ≤ 100000
- 1 ≤ Number written on the Wheel ≤ 1000
- 1 ≤ Q ≤ 10000
- 1 ≤ K ≤ 1000
-  It is guaranteed that K belongs to the N numbers written on the wheel.

-----Example-----
Input:

2

3

1 2 3

3

1

2

3

6

2 1 5 3 2 1

4

1

2

3

5
Output:

3

3

3

2

2

6

6

```python

USER_FILENAME = "<user_code>"
import sys, json, builtins
import math, heapq, bisect, itertools, functools, collections, statistics, fractions, decimal, operator, array, random, re, string, os, pathlib
try:
    import resource as _res
except Exception:
    _res = None
from collections import Counter, defaultdict, deque, OrderedDict
from functools import lru_cache, reduce
from itertools import accumulate, permutations, combinations, product
from math import gcd, ceil, floor, sqrt
from decimal import Decimal
try:
    from typing import *
except Exception:
    pass
try:
    sys.setrecursionlimit(1_000_000)
except Exception:
    pass
try:
    import site as _site
    try:
        _sys_sites = _site.getsitepackages() if hasattr(_site, "getsitepackages") else []
        for _p in _sys_sites:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
    try:
        _usp = _site.getusersitepackages()
        if isinstance(_usp, str):
            _usp = [_usp]
        for _p in _usp:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
except Exception:
    pass

ns = {"__name__": "__main__"}
for _k, _v in list(globals().items()):
    if not _k.startswith("_"):
        ns[_k] = _v
_CODE = 't=int(input())\r\nfor _ in range(t):\r\n    n=int(input())\r\n    arr=list(map(int,input().split()))\r\n    d={}\r\n    for i in range(n):\r\n        if arr[i] in d:\r\n            d[arr[i]].append(i)\r\n        else:\r\n            d[arr[i]]=[i]\r\n    q=int(input())\r\n    for i in range(q):\r\n        m=int(input())\r\n        if len(d[m])==1:\r\n            print(n)\r\n        elif len(d[m])==2:\r\n            print(min((d[m][1]-d[m][0]),((n-d[m][1])+d[m][0])))\r\n        else:\r\n            k=100000\r\n            for j in range(len(d[m])-1):\r\n                if (d[m][j+1]-d[m][j])<k:\r\n                    k=d[m][j+1]-d[m][j]\r\n                else:\r\n                    pass\r\n            print(min(k,((n-d[m][len(d[m])-1])+d[m][0])))\r\n            \r\n                \r\n'
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

```

Measured memory_bytes: 13843