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