def main():
    t = int(input())
    for _ in range(t):
        n = int(input())
        a = list(map(int, input().split()))
        total = 0
        pos_zone = a[0] > 0
        M = 0 if pos_zone else (10 ** 9) * -1
        for c, el in enumerate(a):
            if el > 0:
                if pos_zone:
                    M = max(M, el)
                else:
                    pos_zone = True
                    total += M
                    M = el
            else:
                if not pos_zone:
                    M = max(M, el)
                else:
                    pos_zone = False
                    total += M
                    M = el
            #print(el, pos_zone, M, total)
        total += M
        print(total)
main()