#include <bits/stdc++.h>
using namespace std;
const int dx[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const int dy[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
const int MAX = 1000 * 100 + 10;
const long long INF = 1e18;
const int MOD = 1e9 + 7;
long long len1, len2;
long long get1(vector<long long> v, long long n) {
  long long ans = 0;
  len1 = 0;
  for (long long i = n - 2; i >= 0; i--) {
    if (v[i] > 0 or v[i + 1] > 0) continue;
    v[i] = max(v[i], v[i + 1]);
  }
  for (long long i = 1; i < n; i++) {
    if (v[i] < 0 or v[i - 1] < 0) continue;
    v[i] = max(v[i], v[i - 1]);
  }
  for (long long i = 1; i < n; i++) {
    if (v[i] > 0) continue;
    if (v[i - 1] < 0) continue;
    len1++;
    ans += v[i] + v[i - 1];
  }
  return ans;
}
long long get2(vector<long long> v, long long n) {
  long long ans = 0;
  len2 = 0;
  for (long long i = n - 2; i >= 0; i--) {
    if (v[i] < 0 or v[i + 1] < 0) continue;
    v[i] = max(v[i], v[i + 1]);
  }
  for (long long i = 1; i < n; i++) {
    if (v[i] > 0 or v[i - 1] > 0) continue;
    v[i] = max(v[i], v[i - 1]);
  }
  for (long long i = 1; i < n; i++) {
    if (v[i] < 0) continue;
    if (v[i - 1] > 0) continue;
    ans += v[i] + v[i - 1];
    len2++;
  }
  return ans;
}
void sol() {
  long long n, p(0);
  cin >> n;
  vector<long long> v(n);
  for (long long &i : v) {
    cin >> i;
    p += i > 0;
  }
  if (p == 0 or p == n) {
    sort(v.begin(), v.end());
    cout << v[n - 1] << '\n';
    return;
  }
  long long ans1 = get1(v, n);
  long long ans2 = get2(v, n);
  if (len1 > len2)
    cout << ans1 << '\n';
  else if (len2 > len1)
    cout << ans2 << '\n';
  else
    cout << max(ans1, ans2) << '\n';
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long t = 1;
  cin >> t;
  while (t--) {
    sol();
  }
}
