t = int(input())
import math
for _ in range(t):
    n = int(input())
    l = list(map(int, input().split()))
    pos = 2*int(l[0]>0)-1
    ind = 0
    s = 0
    while ind<n:
        maxi = l[ind]
        while ind < n and pos*l[ind]>=0:
            maxi = max(maxi, l[ind])
            ind+=1

        s+=maxi
        pos*=-1

    print(s)