noc = input()
while noc:
    noc -=1
    ins = raw_input()
    
    while len(set(ins)) > 1:
        ins = "".join(ins.split("01"))
        ins = "".join(ins.split("10"))
        tmp = ins
    print len(ins)