#include <bits/stdc++.h>
using namespace std;
template <typename T>
void trace(const char* name, T&& arg1) {
  cout << name << " : " << arg1 << endl;
}
template <typename T, typename... Args>
void trace(const char* names, T&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " | ";
  trace(comma + 1, args...);
}
bool codejam = 0;
const long long MOD = 1000 * 1000 * 1000 + 7;
const long long NMAX = 1000 * 1000 + 11;
long long arr[NMAX];
long long n, m, p, q, k, a, b, c, ans;
string s, str;
char ch;
vector<long long> v;
long long dp[2];
void solve() {
  cin >> n;
  dp[0] = -LLONG_MAX;
  dp[1] = -LLONG_MAX;
  vector<long long> v;
  for (long long i = 0; i < n; i++) cin >> arr[i];
  for (long long i = 0; i < n;) {
    long long mn = -LLONG_MAX, mx = -LLONG_MAX;
    while (arr[i] < 0 and i < n) {
      mn = max(arr[i], mn);
      i++;
    }
    if (mn != -LLONG_MAX) v.push_back(mn);
    while (arr[i] > 0 and i < n) {
      mx = max(arr[i], mx);
      i++;
    }
    if (mx != -LLONG_MAX) v.push_back(mx);
  }
  long long sum = 0;
  for (auto x : v) sum += x;
  cout << sum;
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  long long cs = 1;
  cin >> t;
  while (t--) {
    if (codejam) {
      cout << "Case #" << cs << ": ";
    }
    cs++;
    solve();
    cout << "\n";
  }
}
