for _ in range(int(input())):
    n = int(input())
    a = list(map(int, input().split()))
    # s = []
    temp = a[0]
    ans = 0
    for i in range(1, n):
        if a[i] > 0:
            if temp > 0:
                temp = max(temp, a[i])
            else:
                # s.append(temp)
                ans += temp
                temp = a[i]
        else:
            if temp < 0:
                temp = max(temp, a[i])
            else:
                # s.append(temp)
                ans += temp
                temp = a[i]
    # s.append(temp)
    # print(s)
    ans += temp
    print(ans)