n=int(raw_input())
while(n):
	s=raw_input()
	x="01"
	y="10"
	while s.count('1')!=0 and s.count('0')!=0:
		d = s.find(x)
		if d != -1:
			s=s.replace(x,"")
		e = s.find(y)
		if e != -1:
			s=s.replace(y,"")
	print len(s)
	n=n-1