for _ in range(int(input())):
    n = int(input())
    a = list(map(int, input().split()))

    b = []
    left, right = 0, 0
    
    for i in range(1, n):
        right = i
        if a[i-1] > 0 and a[i] < 0: 
            if len(b) == 0:
                b.append(max(a[left:right]))
            else:
                b.append(max(a[left:right]))
            left = i 
        elif a[i-1] < 0 and a[i] > 0: 
            if len(b) == 0:
                b.append(max(a[left:right]))
            else:
                b.append(max(a[left:right]))
            left = i 
    
    if len(b)> 0:
        if left == right:
            b.append(a[left])
        else:
            b.append(max(a[left:]))
        print(sum(b))
    else:
        print(max(a))
    
