import sys
input = sys.stdin.readline

t = int(input())

for _ in range(t):
    n = int(input())
    a = list(map(int, input().split()))
    ans = 0
    now = []
    
    for i in range(n-1):
        now.append(a[i])
        
        if a[i]*a[i+1]<0:
            ans += max(now)
            now = []
    
    now.append(a[-1])
    ans += max(now)
    
    print(ans)