if __name__ == "__main__":
    n =  int(input())
    for i in range(n):
        m = int(input())
        ll = [int(i) for i in input().split(' ')]
        is_pos = True
        temp = ll[0]
        is_pos = True if temp > 0 else False
        res = []
        for x in ll:
            if is_pos and x > 0:
                temp = max(x, temp)
            elif is_pos and x < 0:
                res.append(temp)
                is_pos = False
                temp = x
            elif not is_pos and x < 0:
                temp = max(x, temp)
            elif not is_pos and x > 0:
                is_pos = True
                res.append(temp)
                temp = x

        # if is_pos and ll[m-1] > 0:
        res.append(temp)
        print(sum(res))
