
// Problem : C. Alternating Subsequence
// Contest : Codeforces - Codeforces Round #636 (Div. 3)
// URL : https://codeforces.com/problemset/problem/1343/C
// Memory Limit : 256 MB
// Time Limit : 1000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree<int, null_type,less<int>,
// rb_tree_tag,tree_order_statistics_node_update>
// /*
// EXAMPLE
// set is {1, 5, 6, 17, 88}, ie ordered_set oset;
// *(oset.find_by_order(2)) : 3rd element in the set i.e. 6
// oset.order_of_key(6) : Count of elements strictly smaller than 6 is 2.
// */
#define int long long
#define endl '\n'
#define vi vector<int>
#define vb vector<bool>
#define vp vector<pair<int, int>>
#define mod 1000000007
#define M_PI 3.14159265358979323846
#define pint pair<int, int>
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define per(i, b, a) for (int i = b; i >= a; --i)
#define mms(a, n) memset(a, n, sizeof(a))
#define fill(a, value) fill(a.begin(), a.end(), value)
#define all(a) a.begin(), a.end()
#define n_ones(x) __builtin_popcountll(x)
#define pb push_back
#define fi first
#define se second
#define see(args...)                             \
    {                                            \
        cerr << "LINE " << __LINE__;             \
        string _s = #args;                       \
        replace(_s.begin(), _s.end(), ',', ' '); \
        stringstream _ss(_s);                    \
        istream_iterator<string> _it(_ss);       \
        err(_it, args);                          \
        cerr << endl;                            \
    }
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << ' ' << *it << " = " << a;
    err(++it, args...);
}
inline void op() { cout << '\n'; }
template <typename T, typename... Types>
inline void op(T var1, Types... var2) {
    cout << var1 << ' ';
    op(var2...);
}
inline void ip() {}
template <typename T, typename... Types>
inline void ip(T& var1, Types&... var2) {
    cin >> var1;
    ip(var2...);
}
template <typename T, typename U>
inline void min_self(T& x, U y) {
    if (y < x) x = y;
}
template <typename T, typename U>
inline void max_self(T& x, U y) {
    if (x < y) x = y;
}
template <class T1, class T2>
ostream& operator<<(ostream& out, pair<T1, T2> pair) {
    return out << "(" << pair.first << ", " << pair.second << ")";
}
template <class T>
ostream& operator<<(ostream& out, vector<T> vec) {
    out << "(";
    for (auto& v : vec) out << v << ' ';
    return out << ")";
}
template <class T>
ostream& operator<<(ostream& out, set<T> vec) {
    out << "(";
    for (auto& v : vec) out << v << ", ";
    return out << ")";
}
template <class L, class R>
ostream& operator<<(ostream& out, map<L, R> vec) {
    out << "(";
    for (auto& v : vec) out << "[" << v.first << ", " << v.second << "]";
    return out << ")";
}
template <class A, class B>
istream& operator>>(istream& in, pair<A, B>& a) {
    return in >> a.first >> a.second;
}
template <class A>
istream& operator>>(istream& in, vector<A>& a) {
    for (A& i : a) in >> i;
    return in;
}
template <class Container>
void split(const std::string& str, Container& cont, char delim = ',') {
    stringstream ss(str);
    string token;
    while (std::getline(ss, token, delim)) {
        cont.push_back(token);
    }
}

// cout << fixed << setprecision(10) << pi <<" "<<npi<<endl;
// INT64_MAX
// transform(all(s), s.begin(), ::tolower);

int px[4] = {-1, 0, 1, 0};
int py[4] = {0, -1, 0, 1};
struct edge {
    int u, v, wt;
    edge(int a = 0, int b = 0, int c = 0) : u(a), v(b), wt(c) {}
    bool operator<(edge const& other) { return wt < other.wt; }
    friend ostream& operator<<(ostream& out, const edge& x) {
        return out << "(" << x.u << ", " << x.v << ", " << x.wt << ")";
    }
};

void abcd() {
    int n, res = 0;
    ip(n);
    vi a(n);
    ip(a);
    int dp[n][2];  // 0->positive, 1->negative
    mms(dp, 0);
    if (a[0] > 0)
        dp[0][0] = a[0];
    else
        dp[0][1] = a[0];
    rep(i, 1, n - 1) {
        if (a[i] > 0) {
            if (a[i - 1] > 0) {
                dp[i][0] = max(dp[i - 1][1] + a[i], dp[i - 1][0]);
            } else {
                dp[i][0] = dp[i - 1][1] + a[i];
            }
            dp[i][1] = dp[i - 1][1];
        } else {
            if (a[i - 1] < 0) {
                dp[i][1] = max(dp[i - 1][0] + a[i], dp[i - 1][1]);
            } else {
                dp[i][1] = dp[i - 1][0] + a[i];
            }
            dp[i][0] = dp[i - 1][1];
        }
    }
    res = (a[n-1] > 0 ? dp[n-1][0] : dp[n-1][1]);
    op(res);
    return;
}
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t = 1;
    cin >> t;
    while (t--) {
        abcd();
    }
    return 0;
}
