for t in range(int(input())):
    n = int(input())
    arr = list(map(int, input().split()))
    cur = arr[0]
    ans = 0
    sign = arr[0] > 0
    i = 1
    while i < n:
        if not sign ^ (arr[i] > 0):
            cur = max(cur, arr[i])
        else:
            ans += cur
            sign = not sign
            cur = arr[i]
        i += 1
    ans += cur
    print(ans)