def main():
    t = int(input())
    get_sign = lambda x: 1 if x > 0 else -1
 
    for _ in range(t):
        n = int(input())
        seq = [int(i) for i in input().split()]
        dp = [[seq[i], 1, get_sign(seq[i])] for i in range(len(seq))]
        max_len = 0
        max_sum = seq[0]

        for j in range(1, len(seq)):
            si = get_sign(seq[j])

            for i in range(0, j):
                if si != dp[i][2]:
                    if dp[i][1] + 1 > dp[j][1]:
                        dp[j][1] = dp[i][1] + 1
                        dp[j][0] = dp[i][0] + seq[j]
                    elif dp[i][1] + 1 == dp[j][1]:
                        dp[j][0] = max(dp[i][0] + seq[j], dp[j][0])

                if dp[j][1] > max_len:
                    max_len = dp[j][1]
                    max_sum = dp[j][0]
                elif dp[j][1] == max_len:
                    max_sum = max(dp[j][0], max_sum)

        print(max_sum)
 
if __name__ == '__main__':
    main()