def same_sign(a, b):
    if a * b < 0:
        return False
    else:
        return True

def main():
    t = int(input())
    while t:
        t -= 1
        n = int(input())
        a = list(map(int, input().split()))
        max_sum = 0
        if  n == 1:
            print(a[0])
        else:
            i, j = 0, 1
            while n > i:
                while n > j and same_sign(a[i], a[j]):
                    j += 1
                max_sum += max(a[i:j])
                i = j
                j += 1
            print(max_sum)

main()