t=int(input())
for _ in range(t):
    n=int(input())
    arr=list(map(int,input().split()))
    ans=[]
    cur=arr[0]
    flag=0
    if(cur<0):
        flag=0
    else:
        flag=1
    ans.append(cur)
    for i in range(1,n):
        if((flag==0 and arr[i]<0) or (flag==1 and arr[i]>0)):
            ans[-1]=max(arr[i],ans[-1])
        elif((flag==0 and arr[i]>0) or (flag==1 and arr[i]<0)):
            ans.append(arr[i])
            if(arr[i]>0):
                flag=1
            else:
                flag=0
    print(sum(ans))
        