t = int(input())

for l in range(t):
    n = int(input())
    a = list(map(int, input().split()))
    
    sm = 0
    mx = a[0]
    for i in range(1, n):
        if a[i] * a[i-1] <  0:
            sm += mx
            mx = a[i]
        
        elif a[i] > 0:
            mx = max(a[i], mx)
        else:
            mx = max(a[i], mx)
    sm += mx
    print(sm)
        
        