import sys
input = sys.stdin.readline

for _ in range(int(input())):
    n = int(input())
    a = list(map(int, input().split()))
    s = a[0]
    l = a[0]
    for i in range(1,n):
        if a[i]*l < 0:
            l = a[i]
            s += l
        elif l < a[i]:
            s+= a[i] - l
            l = a[i]
    print(s)