import sys
import math

if __name__ == '__main__':
    T = int(sys.stdin.readline())

    for _ in range(T):

        n = int(sys.stdin.readline())
        a = list(map(int, sys.stdin.readline().split()))

        pos = 0
        while pos < n:
            if a[pos] > 0:
                break
            pos += 1
        pos_sum = 0
        pos_len = 0
        pos_flag = True

        while pos < n:
            # print('debug', pos, a[pos])
            if (a[pos] > 0) == pos_flag:
                pos_len += 1
                j_pos = pos
                tmp_max = a[j_pos] + pos_sum
                j_pos += 1
                while j_pos < n and (a[j_pos] > 0) == pos_flag:
                    if tmp_max < a[j_pos] + pos_sum:
                        tmp_max = a[j_pos] + pos_sum
                    j_pos += 1
                pos_sum = tmp_max
                pos = j_pos
                pos_flag = not pos_flag
            else:
                pos += 1

        neg = 0
        while neg < n:
            if a[neg] < 0:
                break
            neg += 1
        neg_sum = 0
        neg_len = 0

        neg_flag = True

        while neg < n:
            if (a[neg] < 0) == neg_flag:
                neg_len += 1
                j_neg = neg
                tmp_max = a[j_neg] + neg_sum
                j_neg += 1
                while j_neg < n and (a[j_neg] < 0) == neg_flag:
                    if tmp_max < a[j_neg] + neg_sum:
                        tmp_max = a[j_neg] + neg_sum
                    j_neg += 1
                neg_sum = tmp_max
                neg = j_neg
                neg_flag = not neg_flag
            else:
                neg += 1

        # print(pos_len)
        # print(neg_len)

        if neg_len > pos_len:
            print(neg_sum)
        elif neg_len < pos_len:
            print(pos_sum)
        else:
            print(max(pos_sum, neg_sum))
