t = int(input())
for _ in range(t):
    n = int(input())
    a = list(map(int, input().split()))

    curr = a[0]
    tot_sum = 0
    for i in range(1, n):
        if curr > 0 and a[i] > 0:
            curr = max(curr, a[i])
        elif curr > 0 and a[i] < 0:
            tot_sum += curr
            curr = a[i]
        elif curr < 0 and a[i] < 0:
            curr = max(curr, a[i])
        elif curr < 0 and a[i] > 0:
            tot_sum += curr
            curr = a[i]

        if i == n - 1:
            tot_sum += curr
    
    if n == 1:
        print(curr)
    else:
        print(tot_sum)