100
04
9
02163
003000
08041479
80750340926070052
90056
11680
90
09020809009020989
00460224000800
0606
6402000040
3918080
31052060072050
41
00070775690
8000780240500799004
66
040934020028
00241600300023700065
3
09964639222895002000
2903002053708649009
000050995
0510000
3000000008000211009
3000
024500407
90000000060100080
08060280
00000040000000000
040064000
00000
10908019020
0050088020
800
298008410740080
1300000720325
40
0310050068000
134808000040007
080030
0036000400404200908
90310
828301135507060000
08900600950000000
82361259068090
02010030000006
74996500183
04
000000003005040000
0390070400100
079
0200603837680020
96902086002730009
7300210000960
3000023906
040000137020007
060648000530003028
0000030709005
80
0980
00700
9560002000040090251
3419288000
07001475020
00095019
0080
60
490040040
04600000069
06805
03006
0880850086926100
5961000060
500810010500000
00009203021
5408
30800
0
8064552300015600040
0305000800
302600
00034000501
0
00400
05006009100304014500
04001745500900450
41136902002070
295400630
90039882
5033107000
000003062
0807005001
710002424009
4900
6009000
640507070179000382
63604043 100
04
9
02163
0
300
108
41479
80
503
09260
0052
90056
11680
90
09
208
900
0
09890
0460
24
00
00006
6864
2
0004
0391
080
3105
06
072
500
10000
077
6906
00
78
2405
0
99004
66
04
9
40
0028
00241
003
0023
0006
03
09964
39222
9500
0000
9
3002
537
864
009
0000
099
205
00000
000
000
8
0
2110
94300
7
24
004
74
00000
00601
0080
080
02
0
00
0004
00
00
0
0004
0640
000
000
1
90
019
20800
00880
0080
02980
84107
008
0130
0007
0
unlucky
unlucky
66
300
80430
807503409967
101
88
unlucky
902080901891
60224000804
12
6402004
9191
52060072054
unlucky
70775690
802405088001
unlucky
934020032
300023941665
unlucky
996464422489
903002118619
unlucky
5100
300000021909
3
500413
90000001068
80610
unlucky
400640
unlucky
90801903
5008802
unlucky
980084107410
3000007211
unlucky
3100500680
808000040015
803
400404236908
94
828301141507
600950000908
82361259077
20100300006
99650032
unlucky
unlucky
9007040013
unlucky
603837680040
969020860336
7300210015
3000038
400001370207
800053006374
unlucky
unlucky
17
70
956000290255
9288008
70014752
95019
8
unlucky
900408
60000019
91
36
880850086936
9610011
810010500005
unlucky
17
83
unlucky
806455290010
5000803
605
34000501
unlucky
40
910030902050
745500900851
41136902009
954011
90057
5033107
unlucky
8070051
710002433
13
9006
707017906445
63611 unlucky
unlucky
66
unlucky
unlucky
unlucky
88
unlucky
unlucky
98
7
101
88
unlucky
unlucky
unlucky
unlucky
unlucky
107
10
unlucky
unlucky
unlucky
24
unlucky
4
13
unlucky
9
unlucky
unlucky
unlucky
10
unlucky
21
unlucky
unlucky
11
unlucky
103
unlucky
unlucky
unlucky
unlucky
10
43
unlucky
5
6
unlucky
109
99
14
0
unlucky
5
unlucky
unlucky
unlucky
0
unlucky
unlucky
unlucky
unlucky
unlucky
unlucky
unlucky
4
97
unlucky
unlucky
unlucky
unlucky
unlucky
61
8
unlucky
unlucky
unlucky
unlucky
4
unlucky
unlucky
unlucky
4
10
unlucky
unlucky
unlucky
unlucky
unlucky
82
88
8
100
92
unlucky
4
7
unlucky
T=input()
best=-1
bound=10**12
boundS=str(bound)
def findBest(s,off,n,sofar):
	#print "looking for best fo",s[off:],n
	remain=len(s)-off
	if remain<n: return
	global best
	if n==1:
		if remain>13:
			return
		if s[off]=="0":
			if len(s)-off>1: return
		if remain==13 and s[off:]!=boundS:
			return
		
		val=sofar+int(s[off:])
		#print "found",val
		if val>best:
			best=val
		return	
	if s[off]=="0":
		findBest(s,off+1,n-1,sofar)
		return
	for i in range(1,min(13,remain-n+2)):
		findBest(s,off+i,n-1,sofar+int(s[off:off+i]))
	if remain-n+1>=13:
		if s[off:off+13]==boundS:
			findBest(s,off+13,n-1,sofar+bound)
for _ in range(T):
	best=-1
	s=raw_input()
	findBest(s,0,4,0)
	if best>=0: print best
	else: print "unlucky"