def func(n,a):
    s = 0
    i = 0
    while i<n:
        max_p = float('-inf')
        if a[i]>0:
            while i<n and a[i]>0:
                max_p = max(a[i],max_p)
                i+=1
            if max_p!=float('-inf'):
                s+=max_p
        else:
            min_n = float('-inf')
            while i<n and a[i]<0:
                min_n = max(a[i],min_n)
                i+=1
            if min_n != float('inf'):
                s+=min_n
    print(s)
for _ in range(int(input())):
    n = int(input())
    l = list(map(int , input().split()))
    func(n,l)
