t = int(input())

for i in range(t):
    n = int(input())
    arr = list(map(int,input().split()))
    newlst=[]
    lst=[arr[0]]
    if(arr[0]>0):
        flag=1
    else:
        flag=-1
    for i in range(1,n):
        if(arr[i]<0 and flag==-1):
            lst.append(arr[i])
        elif(arr[i]<0 and flag==1):
            newlst.append(lst)
            flag=-1
            lst=[]
            lst.append(arr[i])
        elif(arr[i]>0 and flag==1):
            lst.append(arr[i])
        elif(arr[i]>0 and flag==-1):
            newlst.append(lst)
            flag=1
            lst=[]
            lst.append(arr[i])
    if(len(lst)!=0):
        newlst.append(lst)
    ans=0
    for lst in newlst:
        ans+= max(lst)
    print(ans)


