alphanumeric-string

A student is assigned a problem, to get a alphanumeric string from the user and to calculate the sum of digits in the given string.after this he has to delete the digits(0-9) from the string and to display the each word of the string in dictionary order followed by the sum of digits continuously  decreasing by the size of each word(don't print the negative sign).
Help him sought out the problem.

Input:

The first line represents the number of test cases N.
Second line gets the string of length L.

Output:

Display out the string having each word in dictionary order ,each word followed by the sum of the digits continuously decreasing by the size of the word.
if it goes less than 0 than don't print the negative sign only print the digit e.g. (is -4) display it as (is 4).

Constraints:

1 ≤ N<50

0 ≤ L<200

SAMPLE INPUT
2
thi6s is a85 t6es6t
h8e is7 a b9oy5

SAMPLE OUTPUT
a 30 is 28 test 24 this 20
a 28 boy 25 he 23 is 21

Explanation

First line of input represents the number of test cases .
second and third line represents the alphanumeric strings.

In output at first the sum of digits is calculated and then the words of the string are arranged in dictionary order followed by sum of digits subtracted by the size of the word .

Source: hackerearth | Difficulty: UNKNOWN_DIFFICULTY


Solutions:
t = int(input())
for _ in range(0,t):
	s = input()
	num = 0
	for i in s:
		if(i.isdigit()):
			num+=int(i)
	result = ''.join([i for i in s if not i.isdigit()])
	gg = result.split()
	gg.sort()
	for i in range(0,len(gg)):
		if(num - len(gg[i])>0):print(gg[i],num - len(gg[i]), end=' ')
		else:print(gg[i],-1*(num - len(gg[i])), end=' ') 
		num -= len(gg[i])
	print("")


t=eval(input())
for _ in range (t):
	arr=list(map(list,input().strip().split()))
	lis=[]
	for i in arr:
		rlis=[]
		for j in i:
			try:
				
				lis.append(int(j))
				rlis.append(j)
			except ValueError:
				pass
		for k in rlis:
			i.remove(k)
	arr.sort()
	s=sum(lis)
	ans=''
	for i in range (len(arr)):
		m=len(arr[i])
		sm=abs(s-m)
		ans+=(''.join(arr[i])+' '+str(sm)+' ')
		s-=m
	print(ans)


noOfTestCases = int(input())

def outPut(string):
	sum = 0 
	for j in string:
		if(j.isdigit()):
			sum += int(j)
			
	string = ''.join([i for i in string if not i.isdigit()])	
	tokenstrings = string.split(" ")
	sorteTokenstrings = sorted(tokenstrings)
	outputString = ""
	curLen = 0
	for t in sorteTokenstrings:
		curLen += len(t)
		lenToShow = sum - curLen
		if(lenToShow < 0):
			lenToShow = - lenToShow
		outputString += t + " " + str(lenToShow) + " "
	print(outputString)	
 
for no in range(1, noOfTestCases + 1):
	outPut(input())


for _ in range(eval(input())):
	ins = input().strip()
	digs = ''.join(i for i in ins if i.isdigit())   
	digsum = sum((list(map(int,digs))))    
	result = ''.join(i for i in ins if not i.isdigit())
	resarr = result.split()
	resarr = sorted(resarr)
	for x in resarr:
		print(x, end=' ')
		print(str(abs(digsum - len(x))), end=' ')
		digsum -= len(x)
	print()    
	
	
	


t=int(input())
for ti in range(t):
	sum=0
	s=input()
	ns=""
	for i in s:
		if i.isdigit():
			sum=sum+int(i)
		elif i.isalpha():
			ns=ns+str(i)
		elif i==" ":
			ns=ns+" "
	st=list(ns.split(" "))
	st.sort()
	if len(st)==1 and st[0]=='':
		print(sum)
	elif sum==0:
		for i in range(0,len(st)):
			smm=sum-len(st[i])
			print(st[i].strip(),~(smm)+1, end=' ')
			sum=sum-len(st[i])
	else:
		for i in range(0,len(st)):
			sm=sum-len(st[i])
			if sm==0:
				print(st[i].strip(),sm, end=' ')
			elif sm<0:
				print(st[i].strip(),~(sm)+1, end=' ')
			else:
				print(st[i].strip(),(sm*sm)/sm, end=' ')
			sum=sum-len(st[i])
		print()
	
			


t=eval(input())
for _ in range (t):
	arr=list(map(list,input().strip().split()))
	lis=[]
	for i in arr:
		rlis=[]
		for j in i:
			try:
				
				lis.append(int(j))
				rlis.append(j)
			except ValueError:
				pass
		for k in rlis:
			i.remove(k)
	arr.sort()
	s=sum(lis)
	ans=''
	for i in range (len(arr)):
		m=len(arr[i])
		ans+=(''.join(arr[i])+' '+str(abs(s-m))+' ')
		s-=m
	print(ans)


N = eval(input())

def process():
	string = input()
	words = [x for x in string if x not in '1234567890'].split(' ')
	digits = sum(map(int,[x for x in string if x in '1234567890']))
	for i in sorted(words):
		print(i, end=' ')
		digits -= len(i)
		print(abs(digits), end=' ')
	print()

for i in range(N):
	process()