t = int(input())
while t > 0:
    n = int(input())
    a = [int(n) for n in input().split()]
    flag = []
    for i in range(n):
        if a[i] < 0:
            flag.append(0)
        else:
            flag.append(1)
    i, summ, maxx = 0, 0, float("-inf")
    while i < n:
        if a[i] > maxx:
            maxx = a[i]
        if i != n-1:
            if not(flag[i] == flag[i+1]):
                summ += maxx
                maxx = float("-inf")
        i += 1
    print(summ+maxx)
    t -= 1