for _ in range(int(input())):
    n = int(input())
    l = []
    a = list(map(int, input().split()))
    for i in range(n):
        if i == 0 or a[i] < 0 and a[i - 1] > 0 or a[i] > 0 and a[i - 1] < 0:
            l.append([])
        l[-1].append(a[i])
    s = 0
    for i in l:
        s += max(i)
    print(s)