'''
# 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!'
t=input()
while t>0:
	t-=1
	s=raw_input()
	while(1):
		l=len(s)
		s=s.replace("01","")
		s=s.replace("10","")
		if len(s)==l:
			break
		
	print len(s)