from itertools import accumulate

t = int(input())

for _ in range(t):
    n = int(input())
    a = list(map(int, input().split()))
    s = []
    neg = False
    if a[0] < 0:
        neg = True
    
    temp = []
    i = 0
    
    while i < n:
        if neg:
            if a[i] > 0:
                s.append(temp)
                temp = [a[i]]
                neg = False
            else:
                temp.append(a[i])
        else:
            if a[i] > 0:
                temp.append(a[i])
            else:
                s.append(temp)
                temp = [a[i]]
                neg = True
                
        i += 1
                
    s.append(temp)
    
    summ = 0
    for i in s:
        summ += max(i)
        
    print(summ)