def minimumSize(strn):
	strn=map(int,list(strn))
	i=1
	
	
	a=int(strn[0])
	
	
	while i<len(strn):
		a=int(strn[i-1])
		b=int(strn[i])
		if a^b==True:
			del strn[i]
			del strn[i-1]
			i-=1
			if i<1:
				i=1
		else:
			i+=1
			
	return len(strn)

def main():
	T=input()
	result=list()
	for i in range(0,T):
		strn=raw_input()
		N=minimumSize(strn)
		result.append(N)
		
	for i in range(0,T):
		print int(result[i])
	
if __name__ == "__main__":
	main()