'''
22nd april 2020 wednesday
13343 Problem C
'''

for _ in range(int(input())):
    N = int(input())
    a = list(map(int, input().split()))

    i, xsum = 0, 0
    while i < N:
        if a[i] > 0:
            pmax = a[i]
            while i < N and a[i] > 0:
                pmax = max(pmax, a[i])
                i += 1
            xsum += pmax
        else:
            nmax = a[i]
            while i < N and a[i] < 0:
                nmax = max(nmax, a[i])
                i += 1
            xsum += nmax
    
    print(xsum)