test=int(input())
while(test!=0):
    n=int(input())
    arr=[int(x) for x in input().split()]
    segment=[]
    mark=[1]*n
    for i in range(0,n):
        if(arr[i]<0):
            mark[i]=-1
    i=0
    while(i<n):
        x=[]
        x.append(arr[i])
        y=mark[i]
        i+=1
        while(i<n and mark[i]==y):
            x.append(arr[i])
            i+=1
        segment.append(x)
    #print(segment)
    if(len(segment)==1):
        print(-1)
    else:
        maxx=-float('inf')
        curr=0
        for i in range(len(segment)):
            curr+=max(segment[i])
    print(curr)
    test-=1