t=int(input())
for _ in range(t):
    n=int(input())
    a=[int(s) for s in input().split()]
    a.append(0)
    ma=[]
    i=1
    m=[a[0]]
    while i<n:
        while i<n and a[i]*a[i-1]>0:
            m.append(a[i])
            i+=1
        ma.append(m)
        m=[a[i]]
        i+=1
    if a[n-1]*a[n-2]<0:ma.append([a[n-1]])
    print(sum(max(i) for i in ma))