t = int(input())
for w in range(t):
    n = int(input())
    a = [int(x) for x in input().split()]
    ln, m = 1, a[0]
    for i in range(n):
        x = a[i]
        s = a[i]
        l = 1
        for j in range(i + 1, n):
            if a[j] * x < 0:
                x = a[j]
                s += a[j]
                l += 1
        if l > ln:
            ln = l
            m = s
        elif l == ln:
            m = max(s, m)
    print(m)