T = int(input())
for t in range(T):
    N = int(input())
    a = list(map(int, input().split()))
    cur = a[0]
    ans =0
    for i in range(1, N):
        if(a[i]>0 and a[i-1]<0) or(a[i]<0 and a[i-1]>0):
            ans+=cur
            cur=a[i]
        else:
            cur = max(cur, a[i])
    ans+=cur
    print(ans)