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:
from collections import *
from heapq import *
from bisect import *
from math import *
mapper=map
mi=int
mf=float
inf=mf('inf')
ri=raw_input


t=mi(ri())
while t>0:
	t-=1
	s=ri()
	slen=len(s)
	total=0
	before=0
	thr=False
	ass=0
	for i in xrange(slen):
		place=i
		if s[i]=='a' or s[i]=='z':
			ass+=1
			thr=True
			left=before
			right=slen-i-1
			tmp=left+right+(left*right)
			if (left+right)==slen-1:
				tmp-=1
			total+=tmp
			before=0
		else:
			before+=1
	if thr:
		total+=ass+1

	print total