t=int(input())
ultimate=[]
for z in range(t):
    n=int(input())
    ar=[int(i) for i in input().split()]
    ar.append(0)
    final=[]
    sum=0
    big=ar[0]
    for j in range(n):
        if big<ar[j]:
            big=ar[j]
        if j==n-1:
            final.append(big)
            break
        if ar[j]*ar[j+1]<0:
            final.append(big)
            big=ar[j+1]
    for k in final:
        sum+=int(k)
    ultimate.append(sum)
for p in range(t):
    print(ultimate[p])
