test = int(raw_input())
while test>0 :
	n = raw_input()
	one = 0
	zero = 0
	for i in n:
		if i == '1':
			one+=1
		else :
			zero += 1
	ans = len(n)-min(one,zero)*2
	if ans<= 0 :
		print(0)
	else :
		print(ans)
	test-=1