def main():
    T = int(input())
    for _ in range(T):
        _ = int(input())
        A = [int(i) for i in input().split()]
        ans = 0
        cur_max = A[0]
        posi = True if A[0] > 0 else False
        for a in A[1:]:
            if posi:
                if a > 0:
                    cur_max = max(cur_max, a)
                else:
                    ans += cur_max
                    posi = False
                    cur_max = a
            else:
                if a < 0:
                    cur_max = max(cur_max, a)
                else:
                    ans += cur_max
                    posi = True
                    cur_max = a
        print(ans + cur_max)


if __name__ == '__main__':
    main()
