case = int(input())

for j in range(case):
    t = input()
    lst = t.split(" ")

    alt = []
    temp = []
    if int(lst[0]) > 0:
        sign = "p"
    else:
        sign = "n"
    for i in lst:
        if int(i) > 0 and sign == "p":
            temp.append(int(i))
        elif int(i) < 0 and sign == "n":
            temp.append(int(i))
        else:
            alt.append(max(temp))
            temp = [int(i)]
            if sign == "n":
                sign = "p"
            else:
                sign = "n"
    alt.append(max(temp))
    print(sum(alt))