def sign(a):
    if a < 0:
        return -1
    elif a > 0:
        return 1
    else:
        return 0


t = int(input())
for _ in range(t):
    n = int(input())
    a = list(map(int, input().split()))

    s = 0
    i = 0
    while i < len(a):
        max = a[i]
        i += 1
        while i < len(a) and sign(a[i]) == sign(max):
            if a[i] > max:
                max = a[i]
            i += 1
        s += max
    print(s)

