John was learning mathematics and was very bored. Jane his best friend gave him a problem to solve. 
The description of the problem was as follows:- 
You are given a decimal number $N$(1<=$N$<=$10^9$) and three integers $A$, $B$, $C$. 
Steps to perform:
1) You have to create a $LIST$. 
2) You have to initialize the $LIST$ by adding N to the $LIST$ as its first element. 
3) Divide$N$ by $A$ and if the first digit of the fractional part is Non-Zero then add this digit to the  $LIST$ otherwise add the first digit of the integral part(Leftmost digit).
(The integer part or integral part of a decimal is the integer written to the left of the decimal separator.  The part from the decimal separator i.e to the right is the fractional part. )
4) Update $N$  by Last element of the $LIST$. 
N = Last element of $LIST$
5) You have to perform the same process from step 3 on $N$ for $B$ and $C$ respectively 
6) Repeat from step 3 
You have to answer$Q$(1 <= $Q$<= 100 ) queries
For each query you are given an integer $i$ (0 <= $i$ <= $10^9$ ). You have to print the element present at the ith position of the $LIST$. 
Help John solve this problem.

-----Input:-----
- The First Line of input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
- The First Line of each test case contains the  integer $N$.
- The second line of each test case contains three integers $A$, $B$, and $C$ separated by a space
- The third line of each test case contains an integer $Q$.
- Then the next $Q$ line follows.  
- An integer $i$ (0 <= $i$ <= 10^9 )

-----Output:-----
You have to answer the $Q$ queries in the next $Q$ lines. 

-----Constraints-----
- $1 \leq T \leq 10$
- $1 \leq N \leq 10^9$
- $2 \leq A \leq 10$
- $2 \leq B \leq 10$
- $2 \leq C \leq 10$
- $2 \leq Q \leq 100$
- $0 \leq i \leq 10^9$

-----Sample Input:-----
1
56
3 5 7
4
0
1
2
3

-----Sample Output:-----
56
6
2
2

-----EXPLANATION:-----
This list is :
$N$ = 56 and $A$ = 3, $B$ = 5, $C$ = 7. 
Initially $LIST$ = $[ 56 ]$
$N$$/$$A$ =  56/3 = 18.666666666666668 
Add 6 to the $LIST$ 
$LIST$ = $[ 56, 6 ]$
$N$ = 6 
$N$$/$$B$ = 6/5 = 1.2 
Add 2 to the$LIST$ 
$LIST$ = $[ 56, 6, 2 ]$
N = 2 
$N$$/$$C$ = 2/7 =0. 2857142857142857
Add 2 to the $LIST$.  
$LIST$ = $[ 56, 6, 2, 2 ]$
$N$  = 2
We have to keep repeating this process. If any of the numbers got by $N$ dividing by either $A$, $B$, $C$ have 0 after the decimal point then we have to take the first digit of the number. 
for example: if we got 12.005 then here we take 1 and add it to the list and then assign N = 1 
Now the queries ask for the elements at index 0, 1, 2, 3 of the $LIST$ which is 56,6, 2, 2

```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 = "import sys\r\n# sys.stdin = open('input.txt', 'r') \r\n# sys.stdout = open('output.txt', 'w')\r\n \r\nimport math\r\nimport collections\r\nfrom sys import stdin,stdout,setrecursionlimit\r\nimport bisect as bs\r\nsetrecursionlimit(2**20)\r\nM = 10**9+7\r\n    \r\nT = int(stdin.readline())\r\n# T = 1\r\n\r\ndef func(n,a):\r\n    q = n//a; r=n%a\r\n    if(r != 0):\r\n        return((10*r)//a)\r\n    else:\r\n        return(int(str(q)[0]))\r\n\r\nfor _ in range(T):\r\n    n = int(stdin.readline())\r\n    a,b,c = list(map(int,stdin.readline().split()))\r\n    # a = list(map(int,stdin.readline().split()))\r\n    # w = list(map(int,stdin.readline().split()))\r\n    # q = list(map(int,stdin.readline().split()))\r\n    # b = list(map(int,stdin.readline().split()))\r\n    # s = stdin.readline().strip('\\n')  \r\n    g = []\r\n    for i in range(11):\r\n        g.append([0,0,0])\r\n        g[i][0] = func(i,a)\r\n        g[i][1] = func(i,b)\r\n        g[i][2] = func(i,c)\r\n    l = [n]\r\n    l.append(func(l[-1],a))\r\n    l.append(func(l[-1],b))\r\n    l.append(func(l[-1],c))\r\n    cur = l[-1]; ind = 0\r\n    d = {}; st = 4\r\n    while((cur,ind) not in d):\r\n        d[(cur,ind)] = st\r\n        cur = g[cur][ind]\r\n        ind = (ind+1)%3\r\n        l.append(cur)\r\n        st += 1\r\n    st = d[(cur,ind)]; en = len(l)\r\n    sec = en-st\r\n    q = int(stdin.readline())\r\n    # print(l)\r\n    for i in range(q):\r\n        qi = int(stdin.readline())\r\n        if(qi <= st):\r\n            print(l[qi])\r\n            continue\r\n        ans = st + (qi-st)%sec\r\n        print(l[ans])    "
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

```

Measured memory_bytes: 14009