from sys import stdin,stdout
input=stdin.buffer.readline
def allneg(a):
    cc=0
    for x in a:
        if x<0:
            cc+=1
    if cc==len(a):
        return True
    return False
t=int(input())
for _ in range(t):
    n=int(input())
    a=list(map(int,input().split()))
    if allneg(a):
        print(max(a))
        continue
    res=0
    ini=0
    if a[0]>0:
        ini=1
    else:
        ini=-1
    tt=[]
    idx=-1
    for i in range(n):
        if (ini==1 and a[i]>0) or(ini==-1 and a[i]<0):
            tt.append(a[i])
        else:
            idx=i
            break
    res=max(tt)
    fl=1
    if a[0]<0:
        fl=-1
    while 1:
        temp=[]
        while i<n:
            if fl==-1 and a[i]>0:
                temp.append(a[i])
            elif fl==1 and a[i]<0:
                temp.append(a[i])
            else:
                break
            i+=1
        
        #print(temp)
        if temp==[]:
            break
        res+=max(temp)
        fl=-1*fl
    print(res)

