for _ in range(int(input())):
    n=int(input())
    a=list(map(int,input().split()))
    ans=0; mx=a[0]
    for i in range(1,n):
        if a[i]*a[i-1]<0: ans+=mx; mx=a[i]
        elif a[i]>mx: mx=a[i]
    ans+=mx
    print(ans)