Ntc = int(input())

for i in range(Ntc):
    _ = input()
    tc = list(map(int, input().split(' ')))
    ans = 0
    isLastPoolNegative = None
    last = 0
    for c in tc:
        if isLastPoolNegative is None:
            # setup pool
            isLastPoolNegative = c < 0
            last = c
            continue
        # pool changed
        if (c < 0) != isLastPoolNegative:
            # commit last
            ans += last
            # setup pool
            isLastPoolNegative = c < 0
            last = c
            continue
        # in same pool
        if c > last:
            last = c
    # commit last pool
    ans += last
    print(ans)

# for i in range(Ntc):
#     _ = input()
#     tc = list(map(int, input().split(' ')))
#     tc.sort()
#     print(tc)
#     # find first negative index
#     negindex = -1
#     for x in tc:
#         if x > 0:
#             break
#         negindex += 1
#     print(negindex)

#     ans = 0
#     # for half of element
#     for j in range(len(tc) // 2):
#         # if -ve and +ve, alternating
#         if tc[j] < 0 and tc[-(j+1)] > 0:
#             # add sum
#             print(negindex-j, -(j+1))
#             ans += tc[negindex-j] + tc[-(j+1)]
#         else:
#             break
#     print("*", ans if ans else max(tc))
