t = int(input())
for _ in range(t):
    n = int(input())
    l = list(map(int, input().split()))
    if l[0] > 0:
        positive = True
    else:
        positive = False
    curr_el = l[0]
    curr_sum = l[0]
    t_sum = [l[0]]
    if n > 1:
        for x in range(1, n):
            if l[x] > 0 and positive == True:
                if l[x] > t_sum[-1]:
                    t_sum[-1] = l[x]
            elif l[x] < 0 and positive == False:
                if l[x] > t_sum[-1]:
                    t_sum[-1] = l[x]
            elif l[x] > 0 and positive == False:
                positive = True
                t_sum.append(l[x])
            elif l[x] < 0 and positive == True:
                positive = False
                t_sum.append(l[x])
    print(sum(t_sum))