t = int(raw_input())
for test in xrange(t):
    n = int(raw_input())
    a = map(int, raw_input().split())
    result = 0
    start = 0
    for i in xrange(n):
        if i == n - 1 or (a[i] > 0) != (a[i + 1] > 0):
            result += max(a[start : i + 1])
            start = i + 1
    print result
