t=input()
#print t
for _ in range(0,t):
    case=raw_input()
    i=0
    j=0
    for x in range(0,len(case)):
        if case[x]=='1':
            i+=1
        else:
            j+=1
    print abs(i-j)