import sys
# https://codeforces.ml/contest/1343/problem/C
input = sys.stdin.readline
'''
n, m = map(int, input().split())
n=int(input())
A = list(map(int, input().split()))
for test in range(int(input())):
'''
for test in range(int(input())):
    n = int(input())
    A = list(map(int, input().split()))
    A.append(0)
    num = 0
    maxx = 0
    ans = 0
    for a in A:
        if maxx * a > 0:
            maxx = max(maxx, a)
        else:
            num += 1
            ans += maxx
            maxx = a
    print(ans)
