for i in range(input()):
    n = input()
    seq = map(int, raw_input().split())
    # print seq
    out = []
    if n == 1:
        print(''.join(seq))
    else:
        j = 0
        while j < (n-1):
            large = seq[j]
            k = j
            while k < n-1:
                if seq[k]*seq[k+1] < 0:
                    out.append(large)
                    j = k+1
                    if k+1 == n-1:
                        out.append(seq[n-1])
                    k = n-1
                    
                else:
                    if seq[k+1] >= large:
                        large = seq[k+1]
                    k = k + 1
                    if k == n-1:
                        out.append(large)
                        j = n - 1
                        k = n - 1
                    
print sum(map(int, out))