#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
#define asd cout << "\n"
#define pi (3.141592653589)
#define pb push_back
#define mp make_pair
#define sz(x) (x).size()
#define ff first
#define zeroset(a, b) memset(a, b, sizeof(a))
#define ss second
#define rep(i, a, n) for (lli i = a; i < n; i++)
#define rep1(i, a, n) for (int i = a; i <= n; i++)
#define lli long long int
#define li long int
#define ld long double
#define all(x) x.begin(), x.end()
#define mod 1000000007
#define jaldi                         \
    ios_base::sync_with_stdio(false); \
    cin.tie(nullptr);
const int INF = int(1e9);


int findlength(int n)
{
    int ans = 0;
    while (n)
    {
        ans++;
        n = n / 10;
    }
    return ans;
}
int lcm(lli x, lli y)
{
    return (x / __gcd(x, y)) * y;
}
bool prime[100005];
void SieveOfEratosthenes(int n)
{
    memset(prime, true, sizeof(prime));

    for (int p = 2; p * p <= n; p++)
    {
        if (prime[p] == true)
        {
            for (int i = p * p; i <= n; i += p)
                prime[i] = false;
        }
    }
}

unsigned lli factorial(unsigned lli n)
{
    if (n == 0)
        return 1;
    return n * factorial(n - 1);
}
bool isPerfectSquare(long double x)
{
    if (x >= 0)
    {

        long long sr = sqrt(x);
        return (sr * sr == x);
    }
    return false;
}

int findXORofcontino(int n)
{
    int modd = n % 4;
    if (modd == 0)
        return n;
    else if (modd == 1)
        return 1;
    else if (modd == 2)
        return n + 1;
    else if (modd == 3)
        return 0;
    return 0;
}
lli modadd(lli a, lli b, lli MOD = mod)
{
    return ((a % MOD) + (b % MOD) + MOD) % MOD;
}

lli modsub(lli a, lli b, lli MOD = mod)
{
    return ((a % MOD) - (b % MOD) + MOD) % MOD;
}
int get_bit(int n, int pos)
{
    return ((n & (1 << pos)) != 0);
}
int set_bit(int n, int pos)
{
    return (n | (1 << pos));
}
int clear_bit(int n, int pos)
{
    return (n & ~(1 << pos));
}
int no_of_bits(int n)
{
    int ans;
    while (n)
    {
        ans++;
        n = n & n - 1;
    }
    return ans;
}


void solve(){
    lli n;
    cin>>n;
    lli a[n];
    rep(i,0,n)cin>>a[i];
    lli mx,q=0;
    vector<lli>v;
    rep(i,0,n){
        if(i==0){
            mx=a[i];
            if(a[i]>0)q=1;
            if(a[i]<0)q=0;
            if(n==1)v.pb(mx);
            continue;
        }
        int s=0;
        if(a[i]<0)s=0;
        else s=1;
        if(s==q&&i==n-1){
            v.pb(mx);
            continue;
        }
        if(s==q){
            mx=max(mx,a[i]);  
        }
        else{
            v.pb(mx);
            mx=a[i];
            q=s;
            if(i==n-1){
                v.pb(a[i]);
            }
        }
        
    }
    lli sum=0;
    rep(i,0,v.size()){
        sum+=v[i];
    }
    cout<<sum;asd;
    
}       

int main()
{
    jaldi
        #ifndef ONLINE_JUDGE
            freopen("input.txt", "r", stdin);
            freopen("output.txt", "w", stdout);
        #endif
    //cout << fixed << setprecision(9);
    lli t;
    cin >> t;
    while (t--)
    {
        solve();   
    }
}