for _ in range(int(input())):
    n=int(input())
    a=list(map(int,input().split()))
    maxi,s=a[0],0
    for i in range(len(a)):
        if(a[i]*maxi<0):
            s+=maxi
            maxi=a[i]
        else:
            maxi=max(maxi,a[i])
    print(maxi+s)