for i in range(int(input())):
    n = int(input())
    l = list(map(int,input().split()))
    st = l[0]
    su = l[0]
    for i in range(1,n):
        if st > 0 and l[i] < 0 or st < 0 and l[i] > 0:
            su += l[i]
            st = l[i]
        elif st < l[i]:
            su = su - st + l[i]
            st = l[i]
            
    print(su)
        
    