def main(n,a):
    curr_sum=[-9999999999999]*n
    max_sum=[-9999999999999]*n
    curr_sum[0]=a[0]
    max_sum[0]=a[0]
    for i in range(1,n):
        if a[i]*a[i-1]>0:
            variable=curr_sum[i-1]-a[i-1]
            currsum=variable+a[i]
            curr_sum[i]=currsum
            max_sum[i]=max(currsum,max_sum[i-1])
        else:
            curr_sum[i]=a[i]+max_sum[i-1]
            max_sum[i]=curr_sum[i]
    return max_sum[-1]
k=int(input())
for _ in range(k):
    n=int(input())
    a=list(map(int,input().split()))
    print(main(n,a))