# cook your dish here
for _ in range(int(input())):
    n=int(input())
    a=list(map(int,input().split()))
    e=[]
    d=[]
    c=0
    for i in range(len(a)):
        if(a[i]<0):
            d.append(a[i])
            if(len(e)>0):
                ee=max(e)
                c=c+ee
                #print(ee,"YOO")
                e=[]
        else:
            if(len(d)>0):
                aa=max(d)
                c=c+aa
                #print(aa,"OOOO")
            d=[]
            e.append(a[i])
    if(len(e)>0):
        ee=max(e)
        c=c+ee
        #print(ee)
    if(len(d)>0):
        aa=max(d)
        c=c+aa
        #print(aa)
    print(c)
  
            