t = int(input())
while t>0:
    n = int(input())
    a = [int(ele) for ele in input().split()]
    b = []
    prev_taken = ''
    for i in range(len(a)):
        if i == 0:
            b.append(a[i])
            if a[i] > 0:
                prev_taken = 'pos'
            else:
                prev_taken = 'neg'
        else:
            if a[i] > 0 and prev_taken == 'pos':
                if a[i] > b[-1]:
                    b[-1] = a[i]
            
            elif a[i] < 0 and prev_taken == 'neg':
                if a[i] > b[-1]:
                    b[-1] = a[i]
            
            elif (a[i] < 0 and prev_taken == 'pos') or (a[i] > 0 and prev_taken == 'neg'):
                b.append(a[i])
                if a[i] > 0:
                    prev_taken = 'pos'
                else:
                    prev_taken = 'neg'
                
    print(sum(b))
    t -= 1
                