for _ in range(int(input())):
    n = int(input())
    a = list(map(int, input().split()))
    
    s = 0
    i = 0
    
    while i < n:
        maxp = 0
        maxn = 0
        
        while i < n and a[i] < 0:
            if a[i] > maxn or maxn == 0:
                maxn = a[i]
            i += 1
        s += maxn
        
        while i < n and a[i] > 0:
            if a[i] > maxp:
                maxp = a[i]
            i += 1
        s += maxp
        
    print(s)
