t = int(input())
for _ in range(t):
    n = int(input())
    s = list(map(int, input().split()))
    a = [0]
    b = [0]
    m = 0
    cur = 0
    mi = 1
    for i in range(n):
        if s[i] < 0:
            if a[-1] < 0 and s[i] > a[-1]:
                cur -= a[-1]
                cur += s[i]
                a[-1] = s[i]
            elif a[-1] >= 0:
                a.append(s[i])
                cur += s[i]
        else:
            if a[-1] <= 0:
                a.append(s[i])
                cur += s[i]
            elif a[-1] < s[i]:
                cur -= a[-1]
                cur += s[i]
                a[-1] = s[i]
    print(cur)
