from sys import stdin
inp = stdin.readline

t = int(inp().strip())
for _ in range(t):
    n = int(inp().strip())
    array = [int(x) for x in inp().strip().split()]
    ans = []
    prev = array[0]
    max1 = prev
    for i in range(1, n):
        if array[i]>0 and prev <0 or array[i]<0 and prev > 0:
            ans.append(max1)
            if array[i] > 0:
                max1 = 0
            else:
                max1 = -1*(10**9)
        max1 = max(array[i],max1)
        prev = array[i]
    ans.append(max1)
    print(sum(ans))