
for k in range(int(input())):
    n = int(input())
    elements = list(map(int,input().split(" ")))
    max_pos = 0
    min_neg = 0
    if elements[0]>0:
        max_pos = elements[0]
    else:
        min_neg = elements[0]
    sum_e = 0
    for i in range(1,n):
        if elements[i] > 0 and elements[i-1]<0:
            sum_e += min_neg
            min_neg = 0
            max_pos = elements[i]
        elif elements[i] <0 and elements[i-1]>0:
            sum_e += max_pos
            max_pos = 0
            min_neg = elements[i]
        elif max_pos == 0:
            if abs(elements[i])<abs(min_neg):
                min_neg = elements[i]
        else:
            if elements[i]> max_pos:
                max_pos = elements[i]
    sum_e+=min_neg
    sum_e+=max_pos
    print(sum_e)
        