t = int(input())

for tc in range(t):
    n = int(input())
    a = list(map(int, input().split()))

    currlen = 1
    currsum = 0
    curr = a[0]
    i = 0
    while i < n:
        mx = curr
        if curr > 0:
            while i < n and a[i] > 0:
                if a[i] > mx:
                    mx = a[i]
                i += 1
            currsum += mx
        else:
            while i < n and a[i] < 0:
                if a[i] > mx:
                    mx = a[i]
                i += 1
            currsum += mx
        currlen += 1
        if i < n:
            curr = a[i]

    print(currsum)

