for t in range(int(input())):
    n = int(input())
    a = list(map(int, input().split()))
    x = 0
    y = 1
    z = 0
    for q in range(n):
        if a[q] > 0 and a[q] > x:
            if y != 1:
                z = z + x
                x = a[q]
                y = 1
            else:
                x = a[q]
        if a[q] < 0:
            if y == 1:
                z = z + x
                x = a[q]
                y = 0
            elif a[q] > x:
                x = a[q]
        if q == n - 1:
            z = z + x
    print(z)
