n = int(input())
    
for _ in range(n):
    b = int(input())
    a = list(map(int, input().split()))
    
    k, l, c = 0, a[0], 0
    
    if a[0] < 0:
        c = -1
    elif a[0] >0:
        c = 1
    for i in range(1, b):
        if a[i] < 0:
            if c == 1:
                k += l
                l = a[i]
            elif c == -1:
                if l<a[i]:
                    l = a[i]
            c = -1
        elif a[i]>0:
            if c == 1:
                if l<a[i]:
                    l = a[i]
            elif c == -1:
                k += l
                l = a[i]
            c = 1
    print(k + l)
            