t = int(input())
while t:
    t-=1
    length = int(input())
    arr = list(map(int, input().split()))
    dp = []
    sum_dp = []
    for i in range(length):
        dp.append(1)
        sum_dp.append(arr[i])
        for j in range(i):
            if arr[i]*arr[j] < 0 and dp[i] <= dp[j] + 1 :
                dp[i] = dp[j] + 1
                sum_dp[i] = sum_dp[j] + arr[i]
    max_dp = dp[-1]
    max_sum = sum_dp[-1]
    for i in range(length-1, -1, -1):
        if dp[i] == max_dp:
            max_sum = max(sum_dp[i], max_sum)
    print(max_sum)
