for _ in range(int(input())):
    n=int(input())
    a=list(map(int,input().split()))
    lp=0
    ln=0
    sm=list()
    le=a[0]
    for i in range(1,n):
        if (a[i]>0 and le>0) or (a[i]<0 and le<0):
            le=max(le,a[i])
        else:
            sm.append(le)
            le=a[i]
    sm.append(le)
    print(sum(sm))