for _ in range(int(input())):
    n=int(input())
    a=list(map(int,input().split()))
    sumv=0
    j=0
    s=[]
    for e in a:
        if e<0:
            s.append(1)
        else:
            s.append(0)
    if 0 not in s or 1 not in s:
        sumv=max(s)
    else:        
        for i in range(0,n-1):
            if a[i]>0 and a[i+1]<0:
                sumv+=max(a[j:i+1])
                j=i+1
            elif a[i]<0 and a[i+1]>0:
                sumv+=max(a[j:i+1])
                j=i+1
    print(sumv)