#alpha = [ chr(i) for i in range(ord('a'),ord('z')+1)]
arr  = [[],[]]
def out1(x,n,m):
    # print(n,m)
    # if arr[n][m] != True:
    #     return False
    if x <= 0:

        return True
    if n <= 0 :
        if (x-10*m) > 0 :
            # arr[n][m] = False
            return False
        else:
            return True
    if m<=0 :
        # arr[n][m] = False
        return False
    # if n < 1:
    #     return out1(x-10,n,m-1)
    # elif m <= 0:

        
    return out1(x//2+10,n-1,m) or out1(x-10,n,m-1)



def out(x):
    arr = list(map(int,input().split()))
    ans = 0
    flag = True if arr[0] < 0 else False
    # print(neg)
    maxi = arr[0]

    for i in range(x):
        if (flag and arr[i] < 0) or ( not flag and arr[i] > 0):
            maxi = max(maxi,arr[i])
        else:
            ans += maxi
            maxi = arr[i]
            flag = not flag
    
    print(ans+maxi)




for i in range(int(input())):
    x= int(input())
    out(x)
    