def A():
    t = int(input())
    for i in range(t):
        a = []
        n = int(input())
        s = input()
        for num in [int(ss) for ss in s.split(' ')]:
            if len(a) ==0:
                a.append(num)
            elif num*a[len(a)-1]<0 :
                a.append(num)
            elif num > a[len(a)-1]:
                a[len(a)-1] = num
        print(sum(a))           
A()