def alternate(a,n):
    ar = [a[0]]
    large = []
    i = 0
    while(i<(n-1)):
        if a[i]*a[i+1] < 0:
            large.append(max(ar))
            ar = []
            ar.append(a[i+1])
        else:
            ar.append(a[i+1])
        i = i + 1
    large.append(max(ar))
    return sum(large)
    
t = int(input())
for _ in range(t):
    n = int(input())
    a = list(map(int,input().split()))
    print(alternate(a,n))