

T = int(input())

for t in range(T):
    N = input()
    tmp_arr = input()
    arr = [int(x) for x in tmp_arr.split(" ")]

    fPos = True if arr[0] > 0 else False
    suma = [arr[0]]
    for x in arr[1:]:
        if fPos == True and x < 0:
            suma.append(x)
            fPos = False
        elif fPos == False and x > 0:
            suma.append(x)
            fPos = True
        elif x > suma[-1]:
            suma[-1] = x
    print(sum(suma))