t = int(input())
for i in range(t):
    n = int(input())
    l = list(map(int,input().split()))
    su = 0
    sign = 0
    j = 0
    while(j<n):
        if l[j]>0:
            ma = l[j]
            for k in range(j+1,n):
                if l[k]>ma:
                    ma = l[k]
                elif l[k]<0:
                    j = k-1
                    break
                elif k==n-1:
                    j = k
            su+=ma
            #print(ma)
            j+=1
            #print(j)
        elif l[j]<0:
            mi = l[j]
            for k in range(j+1,n):
                if l[k]>mi and l[k]<0:
                    mi = l[k]
                elif l[k]>0:
                    j = k-1
                    break
                elif k==n-1:
                    j = k
            su+=mi
            j+=1
            #print(j)
    print(su)