tc = int(input())
for t in range(tc):
    n = int(input())
    arr = list(map(int, input().split()))
    i = 0
    pos_max = float('-inf')
    neg_min = float('-inf')
    pre = 0
    pn = []
    while i < n:
        if arr[i] > 0:
            pos_max = max(pos_max, arr[i])
            if pre == 1:
                if neg_min != float('-inf'):
                    pn.append(neg_min)
                    neg_min = float('-inf')
                pre = 0
        else:
            neg_min = max(neg_min, arr[i])
            if pre == 0:
                if pos_max != float('-inf'):
                    pn.append(pos_max)
                    pos_max = float('-inf')
                pre = 1
        i += 1
    if pre == 1 and neg_min != float('-inf'):
        pn.append(neg_min)
    elif pre == 0 and pos_max != float('inf'):
        pn.append(pos_max)
    print(sum(pn))
