def cut_num(numlist):
    numlist.append('/')
    i = 1
    while numlist[i]!='/':
        if i == 0:
            i += 1
        elif numlist[i]!= numlist[i-1] and numlist[i] != '/':
            del numlist[i]
            del numlist[i-1]
            i = i-1
        else:
            i += 1

    return(len(numlist)-1)


if __name__=='__main__':
    T = int(raw_input())
    for i in range(0,T):
        numlist = raw_input()
        k = []
        for i in numlist:
            k.append(int(i))
        print cut_num(k)