for _ in range(int(input())):
    n=int(input())
    l=list(map(int,input().split()))
    maxsum=0
    if l[0]<0:
        sign=False
    else:
        sign=True
    i=0;currmax=l[0]
    while i<n:
        if sign:
            if l[i]>0:
                currmax=max(currmax,l[i])
            else:
                maxsum+=currmax
                currmax=l[i]
                sign=False
        else:
            if l[i]<0:
                currmax=max(currmax,l[i])
            else:
                maxsum+=currmax
                currmax=l[i]
                sign=True
        i+=1
    print(maxsum+currmax)
