from sys import stdin

input = stdin.readline


def main():
    test = int(input())

    for t in range(test):
        n = int(input()) // 2
        l = [int(i) for i in input().split(" ")]

        pos = False
        if l[0] > 0:
            pos = True
        maxi = l[0]
        sum = 0

        for i in range(len(l)):
            if pos:
                if l[i] > 0:
                    maxi = max(maxi, l[i])
                else:
                    sum += maxi
                    maxi = l[i]
                    pos = False
            else:
                if l[i] < 0:
                    maxi = max(maxi, l[i])
                else:
                    sum += maxi
                    maxi = l[i]
                    pos = True

        sum += maxi

        print(sum)


main()
