for i in range(input()):
    s=raw_input()
    t=s
    while True:
        if "01" in t:
            t=t.replace("01","")
        elif "10" in t:
            t=t.replace("10","")
        else:
            break
    print len(t)