import math T = int(input()) for i in range(T): n = int(input()) D = list(map(int, input().split())) ans = [] for i in range(9): for j in range(D[i]): ans.append(str(i + 1)) for i in range(9): ans.append(str(0)) print(math.ceil(int("".join(ans)), n) * n)