


T = int(input())
results = []
for case in range(1, T + 1):
    n = int(input())
    a = [int(i) for i in input().split()]
    prev = [a[0]]
    new = []
    su = 0
    for i in range(1, n):
        num = a[i]
        if (num > 0):
            if (a[i - 1] < 0):
                new_num = max(prev)
                new.append(new_num)
                su += new_num
                prev = []
            prev.append(num)
        elif (num < 0):
            if (a[i - 1] > 0):
                new_num = max(prev)
                new.append(new_num)
                su += new_num
                prev = []
            prev.append(num)
    new_num = max(prev)
    su += new_num
    results.append(su)


for result in results:
    print (result)


