t = int(input())
for t1 in range(t):
    n = int(input())
    a = list(map(int, input().split()))
    sum = 0
    max = 0
    i = 0
    while i < n:
        max = a[i]
        it = (-1, 1)[a[i] > 0]
        i += 1
        while i < n and it * a[i] > 0:
            if it > 0 and max < a[i]:
                max = a[i]
            i += 1
        sum += max
    print(sum)