Xavier challenges one of his friend to perform some crazy string functions by giving him some words and each word basically denotes a type of string function which his friend has to perform.

WORDS WITH THEIR MEANING:-

Wordrev n->To arrange each words of the string in reverse order.The last   letter n
denotes upto which letter the words are to be reversed in the   string. For example:-the given string is my name is xavier,the given task is Wordrev 3.Then the output must be ym eman si xavier.The 3 words are reversed because the last letter is 3 that is the task is performed for 3 words,and the remaining are simply dispalyed same as they were.

subpalin n->To find the nth palindrome substring present in the given string.Here n denotes the nth palindrome substring. For eg the string is xyzbabmadamh,the task is subpalin 2.The output must be madam which is the substring of given input string."ababa" is also a palin substring but it   is not the second,it was the first substring.

sortword n->To sort the given string words alphabetically.The letter n denotes the step upto which the sorting is to be done.For example:-The string is he loves to play cricket and the given task is sortword 2.Then the output would be "cricket he to play loves" only the first two words are sorted rest remainsunsorted 

Xaviers friend plans to write a program to solve these questions easily.

Input FORMAT

The first line inputs the String on which the task is to be performed.
Next line denotes number of test cases T.
The next line inputs the T NUMBER tasks to be performed one by one.

Output Format

The output string after the application of each function one by one.

SAMPLE INPUT
my name is xavier
2
Wordrev 3
sortword 2

SAMPLE OUTPUT
ym eman si xavier
is my name xavier
st = raw_input()
task = int(raw_input())
for op in range(task):
	tas, n = raw_input().split()
	n = int(n)
	if tas == "Wordrev":
		k = [''.join(p[::-1]) for p in st.split()]
		l = st.split()
		new = k[:n] + l[n:]
		print ' '.join(new)
	elif tas == "sortword":
		z = st.split()
		z.sort()
		res = z[:n]
		for w in st.split():
			if w not in res:
				res.append(w)
		print ' '.join(res)
	elif tas == "subpalin":
		#print st
		i = 0
		j = 1
		palin = []
		while (i!= len(st)):
			wor = []
			for s in range(i, j+1):
				wor.append(st[s])
			wor = ''.join(wor)	
				
			#print wor	
			if len(wor) >= 2 and wor == wor[::-1]:
				
				#print wor
				palin.append(wor)
				#print palin
			if j < len(st)-1:
				j = j+1
			else:
				i += 1
				j = 1
				#print "hua"
		print palin[n-1]