import sys
import math
import bisect

def solve(A):
    n = len(A)
    B = []
    for a in A:
        if len(B) == 0:
            B.append(a)
        elif B[-1] * a < 0:
            B.append(a)
        else:
            B[-1] = max(B[-1], a)
    return sum(B)

def main():
    for _ in range(int(input())):
        n = int(input())
        A = list(map(int, input().split()))
        print(solve(A))

if __name__ == "__main__":
    main()
