Problem: Alice got a message M. It is in an alien language. A string in an alien language is said to be valid if it contains the letter a or z.  Alice decided to count the number of valid substrings  of the message M. Help him to do this. Two substrings are different if it occurs at different positions in the message.  

Input
First line of the input contains the number of test cases T. It is followed by T lines. Each line has a single string M.  

Output
For each test case, output a single number, the number of valid substrings.   

Constraints
|M| ≤ 10^6 
M contains only lower case latin latters, that is characters a to z.

Read the editorial here.

SAMPLE INPUT
4
abcd
azazaz
abbzbba
flkjdh

SAMPLE OUTPUT
4
21
22
0

Solution (in PYTHON):

Solution:
'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
#print 'Hello World!'

n = int(raw_input())
i = 0
ctr = 0
ans = 0
while i < n:
	tc = raw_input()
	j = 0
	while j < len(tc):
		#print j, " - "
		if tc[j] == 'a' or tc[j] == 'z':
			#ctr = j + 1
			#print "ctr", ctr
			ans += j+1
			ctr = j+1
		else:
			ans += ctr
		#ans = ans + ctr
		#print "ans", ans
		j += 1
	i += 1
	print ans
	ans = 0
	ctr = 0