for _ in range(int(input())):
    n = int(input())
    l = list(map(int,input().split()))
    sum = 0
    i = 0
    while i < n:
        check_out = True if l[i] > 0 else False
        num = l[i]
        for j in range(i+1,n):
            check_in = True if l[j] > 0 else False
            if check_in == check_out:
                num = max(num, l[j])
            else:
                i = j - 1
                break
            if j == n - 1:
                i = j
                break
        sum += num
        i += 1
    print(sum)