for _ in range(int(input())):
    n = int(input())
    a = list(map(int, input().split()))
    s = 0
    i = 0
    while i < n:
        c = a[i]
        while i < n and a[i] * c > 0:
            c= max(a[i], c)
            i += 1
        s += c
    print(s)