t = int(raw_input())
while t>0:
    s = raw_input()
    n = len(s)
    i = 0
    ans = 0
    while i < n:
        if s[i]=='1':
            ans += 1
        else:
            ans -= 1
        i += 1
    if ans < 0:
        print ans*-1
    else:
        print ans
    t-=1