t = int(input())
for _ in range(t):
    n = int(input())
    a = list(map(int, input().split())) + [0]
    arr = []
    pos = 0
    neg = -float('inf')
    for i in range(n):
        if a[i] >= 0:
            pos = max(pos, a[i])
            if a[i+1] <= 0:
                arr.append(pos)
                pos = 0
        elif a[i] < 0:
            neg = max(neg, a[i])
            if a[i+1] >= 0:
                arr.append(neg)
                neg = -float('inf')
    print(sum(arr))
