Frieza wants to become immortal. In order to do that he must acquire all the seven dragon balls. In a legendary fight, he is able to defeat Kami, the Guardian of the dragon balls. Now he has come across a case that contains the dragon balls and he needs your help to open it. 

The case requires a pin number to be unlocked. And the clever Kami has left a puzzle on the case which must be cracked to unlock the case.

On the case, is displayed a string, $S$ of length $N$ consisting of lowercase alphabets. To unlock, he needs to convert this string into a pin number $R$. 

The trick to creating that pin lies in his name $[f, r, i, e, z, a]$. Every character in $S$ is either $good$ or $bad$. It is $good$, if it is a part of the letter set $[f, r, i, e, z, a]$. It is $bad$ otherwise. He'll have to traverse $S$ one by one and count consecutive letters that are $good$ or $bad$ and then store these corresponding counts in the same order in $R$. Thus the pin number, $R$ will be a concatenation of the counts of these letters. See Sample Input for more details.

You have to help him find out $R$.

------ Input: ------

The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. 
Each test case contains a single string $S$ consisting of lowercase characters $[a-z]$.

------ Output: ------
For each test case, output in a single line answer denoting the decoded string which Frieza can use to attain immortality.

------ Constraints  ------
$1 ≤ T ≤ 5$
$1 ≤ N ≤ 10^{5}$
$S$ consists of only lower case alphabets.

----- Sample Input 1 ------ 
2
krillinisdead
futuretrunks
----- Sample Output 1 ------ 
122111221
132114
----- explanation 1 ------ 
*Example case 1:* The string $S$ is "krillinisdead". The letter, "k" does not belong to the set $[f, r, i, e, z, a]$ and hence it's count, i.e., 1 is appended to the string $R$. "ri" belongs to the set $[f, r, i, e, z, a]$ and hence 2 is appended to $R$. "ll" doesn't belong to the set $[f, r, i, e, z, a]$, so it's count 2 is appended to the string $R$. The string $R$ keeps getting updated and the final answer is returned when the input string has been completely traversed.

Source: codechef | Difficulty: EASY


Solutions:
for t in range(int(input())):
	S = input()
	F = 'frieza'
	ci = 0
	cn = 0
	R = ''
	for i in S:
		if i in F:
			if cn > 0:
				R += str(cn)
			ci += 1
			cn = 0
		else:
			if ci > 0:
				R += str(ci)
			cn += 1
			ci = 0
	if cn > 0:
		R += str(cn)
	elif ci > 0:
		R += str(ci)
	print(R)


for i in range(int(input())):
	x = input()
	s = 'frieza'
	c = ''
	for i in x:
		if i in s:
			c += '1'
		else:
			c += '0'
	l = 1
	r = []
	for j in range(len(c) - 1):
		if c[j] == c[j + 1]:
			l += 1
		elif l > 1:
			r.append(l)
			l = 1
		else:
			r.append(l)
	else:
		if c[-1] == c[-2]:
			r.append(l)
		elif l > 1:
			r.append(l - 1)
		else:
			r.append(1)
	print(''.join(map(str, r)))


for n in range(int(input())):
	s = input()
	f = 'frieza'
	chk = ''
	for i in s:
		if i in f:
			chk += '1'
		else:
			chk += '0'
	resp = []
	cnt = 0
	for i in range(len(chk) - 1):
		if chk[i] == chk[i + 1]:
			cnt += 1
		elif cnt > 0:
			resp.append(cnt + 1)
			cnt = 0
		else:
			resp.append(1)
	else:
		if chk[-1] == chk[-2]:
			resp.append(cnt + 1)
		else:
			resp.append(1)
	print(*resp, sep='')


def fun1(N):
	pass
T = int(input())
while T:
	s = input()
	ans = ''
	good = bad = 0
	for c in s:
		if c in 'frieza':
			if good:
				good += 1
			else:
				good = 1
				ans += str(bad)
				bad = 0
		elif bad:
			bad += 1
		else:
			bad = 1
			ans += str(good)
			good = 0
	else:
		ans += str(max(good, bad))
	print(ans[1:])
	T -= 1


t = int(input())
name = ['f', 'r', 'i', 'e', 'z', 'a']
for _ in range(t):
	s = input()
	r = []
	count_in = 1
	val = False
	for i in range(1, len(s)):
		if s[i] in name and s[i - 1] not in name or (s[i - 1] in name and s[i] not in name):
			val = True
		if val:
			r.append(count_in)
			val = False
			count_in = 1
		else:
			count_in += 1
	r.append(count_in)
	string = ''
	for i in range(len(r)):
		string += str(r[i])
	print(string)


for t in range(int(input())):
	s = input()
	r = []
	q = []
	if s[0] in ['f', 'r', 'i', 'e', 'z', 'a']:
		num = 1
		r.append(1)
	else:
		num = 0
		r.append(1)
	for i in range(1, len(s)):
		if s[i] in ['f', 'r', 'i', 'e', 'z', 'a']:
			if num == 0:
				num = 1
				r.append(1)
			elif num == 1:
				r[len(r) - 1] += 1
		elif num == 1:
			num = 0
			r.append(1)
		else:
			r[len(r) - 1] += 1
	q = [str(i) for i in r]
	print(''.join(q))


for _ in range(int(input())):
	c = 0
	s = input()
	l = ['f', 'r', 'i', 'e', 'z', 'a']
	j = s[0]
	for i in s:
		if j in l and i not in l or (i in l and j not in l):
			print(c, end='')
			c = 1
		else:
			c += 1
		j = i
	print(c, end='')
	print()


for i in range(int(input())):
	r = 'frieza'
	s = input()
	c = 1
	for i in range(len(s) - 1):
		if s[i] in r and s[i + 1] in r or (s[i] not in r and s[i + 1] not in r):
			c += 1
		else:
			print(c, end='')
			c = 1
	print(c)


for _ in range(int(input())):
	s1 = 'frieza'
	s = input()
	x = 0
	b = ''
	while x < len(s):
		y = 0
		if s[x] in s1:
			while x < len(s) and s[x] in s1:
				y += 1
				x += 1
		else:
			while x < len(s) and s[x] not in s1:
				y += 1
				x += 1
		b += str(y)
	print(b)


for _ in range(int(input())):
	s = input()
	l = []
	c = 1
	l1 = ['f', 'r', 'i', 'e', 'z', 'a']
	l2 = []
	for i in s:
		if i in l1:
			l.append(1)
		else:
			l.append(0)
	i = 0
	while i < len(s) - 1:
		if l[i] == l[i + 1]:
			c += 1
		else:
			l2.append(c)
			c = 1
		i += 1
	l2.append(c)
	for i in l2:
		print(i, end='')
	print()


letter_set = {'f', 'r', 'i', 'e', 'z', 'a'}
for _ in range(int(input())):
	s = input()
	c = 0
	ans = ''
	appear = False
	for i in range(len(s)):
		if i == 0:
			c = 1
			if s[i] in letter_set:
				appear = True
			else:
				appear = False
		elif int(appear) + int(s[i] in letter_set) == 1:
			ans += str(c)
			appear = s[i] in letter_set
			c = 1
		else:
			c += 1
		if i == len(s) - 1:
			ans += str(c)
	print(ans)


for i in range(int(input())):
	S = input()
	gbS = ''
	for i in range(len(S)):
		if S[i] == 'f' or S[i] == 'r' or S[i] == 'i' or (S[i] == 'e') or (S[i] == 'z') or (S[i] == 'a'):
			gbS += 'g'
		else:
			gbS += 'b'
	count = 1
	length = ''
	if len(gbS) > 1:
		for i in range(1, len(gbS)):
			if gbS[i - 1] == gbS[i]:
				count += 1
			else:
				length += str(count)
				count = 1
		length += str(count)
	else:
		i = 0
		length += str(count)
	print(length)


for _ in range(int(input())):
	s = input()
	li = []
	c = 0
	i = 0
	ns = 'frieza'
	while i < len(s):
		if s[i] in ns:
			while i < len(s) and s[i] in ns:
				c += 1
				i += 1
			li.append(c)
			c = 0
		elif s[i] not in ns:
			while i < len(s) and s[i] not in ns:
				c += 1
				i += 1
			li.append(c)
			c = 0
	for j in li:
		print(j, end='')
	print()


for _ in range(int(input())):
	a = input()
	chk = 'frieza'
	res = ''
	y = 0
	n = 0
	temp_n = []
	temp_y = []
	for i in a:
		if i in chk:
			if len(temp_n) != 0:
				res = res + str(max(temp_n))
				n = 0
				y += 1
				temp_y.append(y)
				temp_n = []
			else:
				n = 0
				y += 1
				temp_y.append(y)
				temp_n = []
		elif len(temp_y) != 0:
			res = res + str(max(temp_y))
			y = 0
			n += 1
			temp_n.append(n)
			temp_y = []
		else:
			y = 0
			n += 1
			temp_n.append(n)
			temp_y = []
	if len(temp_y) != 0:
		res = res + str(max(temp_y))
	if len(temp_n) != 0:
		res = res + str(max(temp_n))
	print(res)


for i in range(int(input())):
	s = input()
	(val, count) = (-1, 0)
	l = ['f', 'r', 'i', 'e', 'z', 'a']
	l1 = []
	for x in s:
		if x in l:
			if val == 1:
				l1.append(str(count))
				count = 0
			val = 0
			count += 1
		else:
			if val == 0:
				l1.append(str(count))
				count = 0
			val = 1
			count += 1
	l1.append(count)
	for x in l1:
		print(x, end='')
	print()


goodSet = ['f', 'r', 'i', 'e', 'z', 'a']
n = int(input())
for line in range(n):
	s = input()
	R = ''
	count = 0
	good = True if s[0] in goodSet else False
	for char in s:
		if char in goodSet:
			if good:
				count += 1
			else:
				R += str(count)
				good = True
				count = 1
		elif not good:
			count += 1
		else:
			R += str(count)
			good = False
			count = 1
	print(R + str(count))


for _ in range(int(input())):
	s = input()
	n = len(s)
	i = 0
	imor = ''
	while i < n:
		j = i + 1
		temp = 1
		if s[i] == 'f' or s[i] == 'r' or s[i] == 'i' or (s[i] == 'e') or (s[i] == 'z') or (s[i] == 'a'):
			while j < n:
				if s[j] == 'f' or s[j] == 'r' or s[j] == 'i' or (s[j] == 'e') or (s[j] == 'z') or (s[j] == 'a'):
					j = j + 1
					temp = temp + 1
				else:
					break
		else:
			while j < n:
				if s[j] != 'f' and s[j] != 'r' and (s[j] != 'i') and (s[j] != 'e') and (s[j] != 'z') and (s[j] != 'a'):
					j = j + 1
					temp = temp + 1
				else:
					break
		imor = imor + str(j - i)
		i = j
	print(imor)


T = int(input())
for _ in range(T):
	s = input()
	d = ['f', 'r', 'i', 'e', 'z', 'a']
	a = 0
	b = 0
	c = 0
	result = ''
	for i in s:
		c += 1
		if i in d:
			a += 1
			if b != 0:
				result += str(b)
			b = 0
		else:
			b += 1
			if a != 0:
				result += str(a)
			a = 0
		if c == len(s):
			if a == 0:
				result += str(b)
			else:
				result += str(a)
	print(result)


for t in range(int(input())):
	s = input()
	ploy = 'frieza'
	mack = ''
	b = None
	current = 0
	for i in range(len(s)):
		if s[i] in ploy and b is None:
			current = i
			b = True
		if s[i] not in ploy and b is None:
			current = i
			b = False
		if s[i] in ploy and b is False:
			mack += str(i - current)
			current = i
			b = True
		if s[i] not in ploy and b or b is None:
			mack += str(i - current)
			current = i
			b = False
	mack += str(len(s) - current)
	print(mack)


test_cases = int(input())
for i in range(test_cases):
	string = input()
	output = ''
	good = 0
	bad = 0
	for i in range(len(string)):
		if string[i] == 'f' or string[i] == 'r' or string[i] == 'i' or (string[i] == 'e') or (string[i] == 'z') or (string[i] == 'a'):
			if bad != 0:
				output = output + str(bad)
			good = good + 1
			bad = 0
		else:
			if good != 0:
				output = output + str(good)
			bad = bad + 1
			good = 0
	if good != 0:
		output = output + str(good)
	if bad != 0:
		output = output + str(bad)
	print(output)


code = set('frieza')
for _ in range(int(input())):
	S = input().strip()
	cur = 0
	binary = ''
	cur_code = 0
	for c in S:
		if c in code and cur and (cur_code == 0):
			binary += str(cur)
			cur_code = 1
			cur = 0
		elif c in code and cur == 0:
			cur_code += 1
		elif c not in code and cur_code == 0:
			cur += 1
		else:
			binary += str(cur_code)
			cur_code = 0
			cur = 1
	else:
		if cur > 0:
			binary += str(cur)
		else:
			binary += str(cur_code)
	print(binary)


T = int(input())
for i in range(T):
	S = input()
	(i, j) = (0, 0)
	(c, d) = (0, 0)
	a = ' '
	f = {'f', 'r', 'i', 'e', 'z', 'a'}
	while j < len(S):
		if S[j] in f:
			if d > 0:
				a = a + str(d)
			c += 1
			d = 0
			j += 1
		elif S[j] not in f:
			if c > 0:
				a = a + str(c)
			d += 1
			c = 0
			j += 1
		if j == len(S):
			if c > 0:
				a = a + str(c)
			if d > 0:
				a = a + str(d)
	print(a)


t = int(input())
while t:
	s = input()
	req = 'frieza'
	res = ''
	k = 0
	while k < len(s):
		l = 0
		if s[k] in req:
			while k < len(s) and s[k] in req:
				l += 1
				k += 1
		else:
			while k < len(s) and s[k] not in req:
				l += 1
				k += 1
		res += str(l)
	print(res)
	t -= 1


t = int(input())
for i in range(t):
	s = input()
	sen = 'frieza'
	ans = ''
	j = 0
	while j < len(s):
		c = 0
		if s[j] in sen:
			while j < len(s) and s[j] in sen:
				c += 1
				j += 1
		else:
			while j < len(s) and s[j] not in sen:
				c += 1
				j += 1
		ans += str(c)
	print(ans)


for _ in range(int(input())):
	S = input()
	s = ''
	i = 0
	while i < len(S):
		c = 0
		if S[i] in 'frieza':
			while i < len(S) and S[i] in 'frieza':
				c += 1
				i += 1
		else:
			while i < len(S) and S[i] not in 'frieza':
				c += 1
				i += 1
		s += str(c)
	print(s)


for i in range(int(input())):
	s = input()
	name = ['f', 'r', 'i', 'e', 'z', 'a']
	result = ''
	a = 0
	b = 0
	c = 0
	for i in s:
		c += 1
		if i in name:
			a += 1
			if b != 0:
				result += str(b)
			b = 0
		else:
			b += 1
			if a != 0:
				result += str(a)
			a = 0
		if c == len(s):
			if a == 0:
				result += str(b)
			else:
				result += str(a)
	print(result)


t = int(input())
while t > 0:
	s = input()
	length = ''
	i = 0
	while i < len(s):
		c = 0
		if s[i] in 'frieza':
			while i < len(s) and s[i] in 'frieza':
				c = c + 1
				i = i + 1
		else:
			while i < len(s) and s[i] not in 'frieza':
				c = c + 1
				i = i + 1
		length = length + str(c)
	print(length)
	t = t - 1


T = int(input())
for i in range(T):
	str1 = input()
	length = ''
	i = 0
	while i < len(str1):
		count = 0
		if str1[i] in 'frieza':
			while i < len(str1) and str1[i] in 'frieza':
				count += 1
				i += 1
		else:
			while i < len(str1) and str1[i] not in 'frieza':
				count += 1
				i += 1
		length += str(count)
	print(length)


for _ in range(int(input())):
	s = input()
	n = len(s)
	count1 = count2 = 1
	sol = ''
	count = 0
	for i in range(n):
		if s[i] in 'frieza':
			count1 = 0
			if count2 == 0:
				count2 = 1
				sol = sol + str(count)
				count = 1
			else:
				count += 1
		else:
			count2 = 0
			if count1 == 0:
				count1 = 1
				sol = sol + str(count)
				count = 1
			else:
				count += 1
	sol = sol + str(count)
	length = len(sol)
	for i in range(length):
		print(sol[i], end='')
	print()


for i in range(int(input())):
	text = input()
	list = ['f', 'r', 'i', 'e', 'z', 'a']
	num = []
	count = 0
	name = 1
	for j in text:
		if j in list:
			if name == 1:
				count += 1
			else:
				if count != 0:
					num.append(count)
				name = 1
				count = 0
				count += 1
		elif name == 0:
			count += 1
		else:
			if count != 0:
				num.append(count)
			name = 0
			count = 0
			count += 1
	num.append(count)
	for h in num:
		print(h, end='')
	print()


t = int(input())
for ni in range(t):
	s = input()
	for i in s:
		if i == 'f' or i == 'r' or i == 'i' or (i == 'e') or (i == 'z') or (i == 'a'):
			s = s.replace(i, '1')
		else:
			s = s.replace(i, '0')
	if s[0] == '0':
		x = '0'
	else:
		x = '1'
	r = [0] * len(s)
	j = 0
	r[j] = 1
	for i in range(1, len(s)):
		if s[i] == '0' and x == '0':
			x = '0'
			r[j] = r[j] + 1
		elif s[i] == '0' and x == '1':
			x = '0'
			j = i
			r[j] = r[j] + 1
		elif s[i] == '1' and x == '0':
			x = '1'
			j = i
			r[j] = r[j] + 1
		elif s[i] == '1' and x == '1':
			x = '1'
			r[j] = r[j] + 1
	z = ''
	for i in range(len(r)):
		if r[i] != 0:
			z = z + str(r[i])
	print(z)


import re
for tc in range(int(input())):
	s = input()
	x = re.findall('[^frieza]+|[frieza]+', s)
	for i in x:
		print(len(i), end='')
	print()


t = int(input())
while t != 0:
	s = input()
	g = b = 0
	r = ''
	for x in s:
		if x in 'freiza':
			if b != 0:
				r = r + str(b)
				b = 0
			g += 1
		else:
			if g != 0:
				r += str(g)
				g = 0
			b += 1
	if g != 0:
		r += str(g)
	else:
		r += str(b)
	print(r)
	t -= 1


def goodbad(l):
	l = list(l)
	goodcount = 0
	badcount = 0
	count = ''
	for i in range(len(l)):
		if l[i] in ['f', 'r', 'i', 'e', 'z', 'a']:
			goodcount += 1
			if badcount != 0:
				count += str(badcount)
				badcount = 0
		else:
			if goodcount != 0:
				count += str(goodcount)
				goodcount = 0
			badcount += 1
	if goodcount != 0:
		count += str(goodcount)
	if badcount != 0:
		count += str(badcount)
	return count
for _ in range(int(input())):
	print(goodbad(input()))


from itertools import groupby
for _ in range(int(input())):
	s = str(input())
	num = ''
	for i in s:
		count = 0
		if i in 'frieza':
			count += 1
		num += str(count)
	v = ''
	groups = groupby(num)
	result = [(label, sum((1 for _ in group))) for (label, group) in groups]
	for (i, j) in result:
		v += str(j)
	print(v)


t = int(input())
for x in range(t):
	sen = input()
	s = ''
	for c in sen:
		if c in 'frieza':
			s += 'Y'
		else:
			s += 'N'
	r = ''
	count = 0
	last = s[0]
	for c in s:
		if c == last:
			count += 1
		else:
			r += str(count)
			count = 1
			last = c
	r += str(count)
	print(r)


def word_to_numstr(word):
	name = 'frizea'
	num_str = ''
	for a in word:
		if a in name:
			num_str += str(1)
		else:
			num_str += str(0)
	return num_str

def get_final_numstr(word):
	count = 1
	str_a = ''
	x = 0
	for a in range(len(word) - 1):
		if word[a] == '0' and word[a + 1] == '0' or (word[a] == '1' and word[a + 1] == '1'):
			count += 1
			x = 0
		else:
			str_a += str(count)
			count = 1
			x = 1
	return str_a + str(count)
for t in range(int(input())):
	given_word = input()
	num_str = word_to_numstr(given_word)
	print(get_final_numstr(num_str))


t = int(input())
for dummy in range(t):
	sraw = input()
	s = ''
	for c in sraw:
		if c in 'frieza':
			s += 'Y'
		else:
			s += 'N'
	r = ''
	count = 0
	last = s[0]
	for c in s:
		if c == last:
			count += 1
		else:
			r += str(count)
			count = 1
			last = c
	r += str(count)
	print(r)


l = 'frieza'
for _ in range(int(input())):
	s = list(input())
	ans = ''
	c = 0
	f = 0
	for i in range(len(s)):
		if s[i] in l:
			s[i] = 1
		else:
			s[i] = 0
	for j in range(1, len(s)):
		if s[j] == s[j - 1]:
			c += 1
		else:
			ans += str(c + 1)
			c = 0
	ans += str(c + 1)
	print(ans)


G = ['f', 'r', 'i', 'e', 'z', 'a']
for i in range(int(input())):
	S = input()
	S = list(S)
	P = []
	inc = 0
	notinc = 0
	for j in S:
		if j in G:
			if notinc != 0:
				P.append(str(notinc))
				notinc = 0
			inc = inc + 1
		else:
			if inc != 0:
				P.append(str(inc))
				inc = 0
			notinc = notinc + 1
	if inc != 0:
		P.append(str(inc))
	else:
		P.append(str(notinc))
	P = ''.join(P)
	print(P)


a = ['f', 'r', 'i', 'e', 'z', 'a']
for t in range(int(input())):
	s = input()
	c = 0
	b = True if s[0] in a else False
	res = ''
	for i in range(len(s)):
		if s[i] in a:
			if not b:
				b = True
				res += str(c)
				c = 0
		elif b:
			b = False
			res += str(c)
			c = 0
		c += 1
	res += str(c)
	print(res)


for i in range(int(input())):
	string = input()
	ans = ''
	words = 'frieza'
	total = 1
	cur = 0
	if string[0] in words:
		cur = 0
	else:
		cur = -1
	for i in range(1, len(string)):
		if string[i] in words and cur == 0:
			total += 1
		elif string[i] not in words and cur == -1:
			total += 1
		elif string[i] in words and cur == -1:
			ans += str(total)
			total = 1
			cur = 0
		else:
			ans += str(total)
			total = 1
			cur = -1
	print(ans + str(total))


t = int(input())
z = 0
while z < t:
	l = input()
	x = ['f', 'r', 'i', 'e', 'z', 'a']
	ct = 1
	y = []
	for i in range(1, len(l)):
		if l[i] in x and l[i - 1] in x:
			ct += 1
			if i == len(l) - 1:
				y.append(ct)
		elif l[i] not in x and l[i - 1] not in x:
			ct += 1
			if i == len(l) - 1:
				y.append(ct)
		else:
			y.append(ct)
			ct = 1
			if i == len(l) - 1:
				y.append(ct)
	for i in range(len(y)):
		print(y[i], end='')
	print()
	z += 1


t = int(input())
F = {'f', 'r', 'i', 'e', 'z', 'a'}
for i in range(t):
	ans = ''
	pcount = 0
	ncount = 0
	N = input()
	for j in N:
		if j in F:
			if ncount > 0:
				ans = ans + str(ncount)
			pcount += 1
			ncount = 0
		else:
			if pcount > 0:
				ans = ans + str(pcount)
			ncount += 1
			pcount = 0
	if pcount > 0:
		ans = ans + str(pcount)
	if ncount > 0:
		ans = ans + str(ncount)
	print(ans)


for _ in range(int(input())):
	s = list(input())
	a = ['f', 'r', 'i', 'e', 'z', 'a']
	ans = ''
	c = 0
	f = 0
	for i in range(len(s)):
		if s[i] in a:
			s[i] = 1
		else:
			s[i] = 0
	for i in range(1, len(s)):
		if s[i] == s[i - 1]:
			c += 1
		else:
			ans += str(c + 1)
			c = 0
	ans += str(c + 1)
	print(ans)


name = 'frieza'
for i in range(int(input())):
	s = input()
	l = []
	a = []
	for i in s:
		if i in name:
			l.append('Good')
		else:
			l.append('Bad')
	if l[-1] == 'Good':
		l.append('Bad')
	else:
		l.append('Good')
	good = 0
	bad = 0
	for j in range(len(l)):
		if l[j] == 'Good':
			a.append(bad)
			good += 1
			bad = 0
		if l[j] == 'Bad':
			a.append(good)
			bad += 1
			good = 0
	for i in range(len(a)):
		if i != len(a) - 1 and a[i] != 0:
			print(a[i], end='')
		elif i == len(a) - 1 and a[i] != 0:
			print(a[i])


l = ['f', 'r', 'i', 'e', 'z', 'a']
for i in range(int(input())):
	st = ''
	(b, g) = (0, 0)
	lst = list(input())
	for x in lst:
		if x in l:
			if b > 0:
				st += str(b)
			b = 0
			g += 1
		else:
			if g > 0:
				st += str(g)
			g = 0
			b += 1
	if b > 0:
		print(st + str(b))
	else:
		print(st + str(g))


name = ['f', 'r', 'i', 'e', 'z', 'a']

def bad_or_good(a):
	if a in name:
		return 'good'
	return 'bad'

def main(string):
	string_type = None
	r = ''
	count = 0
	for i in string:
		if string_type is None:
			string_type = bad_or_good(i)
			count += 1
			continue
		elif string_type == bad_or_good(i):
			count += 1
		else:
			r += str(count)
			count = 1
			string_type = bad_or_good(i)
	return r + str(count)
for _ in range(int(input())):
	s = input()
	r = main(s)
	print(r)


for _ in range(int(input())):
	s = input()
	count = 0
	r = ''
	name = ['f', 'r', 'i', 'e', 'z', 'a']
	bad = False
	good = False
	for i in range(len(s)):
		if s[i] not in name:
			if good:
				r += str(count)
				count = 0
				good = False
			bad = True
		else:
			if bad:
				r += str(count)
				count = 0
				bad = False
			good = True
		count += 1
	if count > 0:
		r += str(count)
	print(r)


l = ['f', 'r', 'i', 'e', 'z', 'a']

def getchartype(char):
	if char in l:
		return 'good'
	return 'bad'

def get_code(s):
	code = ''
	lastchartype = None
	conscount = 0
	for char in s:
		if lastchartype == None:
			lastchartype = getchartype(char)
			conscount = 1
			continue
		if lastchartype == getchartype(char):
			conscount += 1
		else:
			code += str(conscount)
			conscount = 1
			lastchartype = getchartype(char)
	return code + str(conscount)
Input = [input() for i in range(0, int(input()))]
for s in Input:
	print(get_code(s))


a = ['f', 'r', 'i', 'e', 'z', 'a']
t = int(input())
while t:
	s = list(input())
	count = 0
	for i in range(len(s)):
		if s[i] in a:
			s[i] = 1
		else:
			s[i] = 0
	count = 1
	for j in range(len(s) - 1):
		if s[j] == 0:
			if s[j] == s[j + 1]:
				count += 1
			else:
				print(count, end='')
				count = 1
		elif s[j] == s[j + 1]:
			count += 1
		else:
			print(count, end='')
			count = 1
	print(count)
	t -= 1