for _ in range(int(input())):
    input()
    a = list(map(int, input().split()))
    x, r = a[0], 0
    for i in a[1:]:
        if i * x < 0: r += x; x = i
        if i < 0 and i > x: x = i
        if i > 0 and i > x: x = i
    print(r + x)