no=int(input())
for ll in range(no):
    n = int(input())
    a = [i for i in map(int, input().split())]
    ans = []
    x = 0
    ans = [a[0]]
    for i in range(1, n):
        if (ans[-1] > 0):
            if (a[i] > 0 and a[i] > ans[-1]):
                ans = ans[:-1]
                ans.append(a[i])
            if (a[i] < 0):
                ans.append(a[i])
        else:
            if (a[i] < 0 and a[i] > ans[-1]):
                ans = ans[:-1]
                ans.append(a[i])
            if (a[i] > 0):
                ans.append(a[i])

    print(sum(ans))

