def read():
    return list(map(lambda x: int(x), input().split()))


T = read()[0]

for t in range(T):
    n = read()[0]
    nums = read()
    sign = nums[0]
    valid = []
    for i in range(n):
        if sign * nums[i] > 0:
            sign = max(sign, nums[i])
        else:
            valid.append(sign)
            sign = nums[i]
    valid.append(sign)
    valid_n = len(valid)
    # ans = [
    #     [0, 0] for _ in range(valid_n)
    # ]
    # if valid[0] < 0:
    #     ans[0][0] = valid[0]
    # else:
    #     ans[0][1] = valid[0]

    # for i in range(1, valid_n):
    #     if valid[i] < 0:
    #         ans[i][1] = ans[i-1][1]
    #         ans[i][0] = max(ans[i-1][0], ans[i-1][1] + valid[i])
    #     else:
    #         ans[i][0] = ans[i-1][0]
    #         ans[i][1] = max(ans[i-1][1], ans[i-1][0] + valid[i])

    # print(max(ans[-1][0], ans[-1][1]))
    print(sum(valid))
