t = int(input())

for _ in range(t):
    n = int(input())
    arr = list(map(int,input().split()))
    dp = [0]*n
    dp[0] = arr[0]
    p = None
    sign = lambda a:1 if a>0 else -1
    j = 1
    while j < n:
        if sign(arr[j]) == sign(arr[j-1]):
            dp[j] = max(dp[j-1],arr[j])
        else:
            p = j-1
            break
        j+=1


    while j < n:
        if sign(arr[j]) == sign(arr[j-1]):
            dp[j] = max(dp[p]+arr[j],dp[j-1])
        else:
            dp[j] = dp[j-1]+arr[j]
            p = j-1
        j+=1

    print(dp[n-1])        


    