for _ in range(int(input())):
    n = int(input())
    a = list(map(int, input().split()))
    s = 1 if a[0] > 0 else -1
    a += [0]
    total = 0
    mx = a[0] 
    for i in range(n+1):
        if s==1 and a[i] > 0:
            mx = max(a[i], mx)
        elif s == 1 and a[i] < 0:
            total += mx
            mx = a[i]
            s = -1
        elif s == -1 and a[i] < 0:
            mx = max(a[i], mx)
        elif s == -1 and a[i] > 0:
            total += mx
            mx = a[i]
            s = 1
        elif a[i] == 0: total += mx
    print(total)