t = int(input())
for _ in range(t):
    n = int(input())
    a = list(map(int, input().split()))
    b = []
    i = 1
    m = a[0]
    while i < len(a):
        if a[i] > 0:
            if a[i-1]>0:
                m = max(a[i],m)
            else:
                b.append(m)
                m = a[i]
        else:
            if a[i-1]<0:
                m = max(a[i],m)
            else:
                b.append(m)
                m = a[i]
        i+=1
        
    b.append(m)
    print(sum(b))