from math import ceil, gcd, sqrt, floor
from collections import Counter, defaultdict, deque
import heapq
from math import ceil,log2;
def modM(a, b, M):
return (a%M * b%M)%M
def gL(): return list(map(int, input().split()))
def gT(): return tuple(map(int, input().split()))
def gI(): return int(input())
def pR(ok):
if ok:
print("yes")
else:
print("no")
tt = 1
tt = int(input())
def solve():
n = gI()
a = list(input())
res = float('inf')
for i in range(n-1):
temp = []
tot = 0
j = 0
while j < n:
curr = []
curr.append(a[j])
if i == j:
curr.append(a[j+1])
j += 1
temp.append(''.join(curr))
j += 1
tot = int(temp[0])
for j in range(1, len(temp)):
tot = min(tot * int(temp[j]), tot + int(temp[j]))
res = min(res, tot)
print(res)
for i in range(tt):
solve()
151C - Win or Freeze | 1585A - Life of a Flower |
1662A - Organizing SWERC | 466C - Number of Ways |
1146A - Love "A" | 1618D - Array and Operations |
1255A - Changing Volume | 1710C - XOR Triangle |
415C - Mashmokh and Numbers | 8A - Train and Peter |
591A - Wizards' Duel | 1703G - Good Key Bad Key |
1705A - Mark the Photographer | 1707A - Doremy's IQ |
1706B - Making Towers | 1325B - CopyCopyCopyCopyCopy |
1649C - Weird Sum | 1324B - Yet Another Palindrome Problem |
525A - Vitaliy and Pie | 879A - Borya's Diagnosis |
1672B - I love AAAB | 1673A - Subtle Substring Subtraction |
1345A - Puzzle Pieces | 711A - Bus to Udayland |
779B - Weird Rounding | 1703D - Double Strings |
1704C - Virus | 63A - Sinking Ship |
1704B - Luke is a Foodie | 298B - Sail |