def solve():
    n = int(input())
    a = list(map(int, input().split()))
    ans = 0
    Q = [a[0]]
    for i in range(1, n):
        if Q[-1]*a[i] > 0:
            Q.append(a[i])
        else:
            ans += max(Q)
            Q.clear()
            Q.append(a[i])
    if Q:
        ans += max(Q)
    print(ans)
    return


def main():
    t = int(input())
    for i in range(t):
        solve()
    return


if __name__ == "__main__":
    main()

