def sign(k):
    return 1 if k > 0 else -1


for _ in range(int(input())):
    n = int(input())
    a = list(map(int, input().split()))

    ans = 0
    last_index = 0
    for i in range(1, n):
        if a[i] * a[i-1] < 0:
            # print(i)
            ans += max(a[last_index:i])
            # print('ans += {}'.format(max(a[last_index:i])))
            last_index = i
    print(ans + max(a[last_index:n]))


