#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const long long inf = 1e18 + 5;
const long long MX = 303030;
int cox[4] = {1, -1, 0, 0};
int coy[4] = {0, 0, 1, -1};
int dx[] = {-1, 0, 1, 0, -1, +1, +1, -1};
int dy[] = {0, 1, 0, -1, +1, +1, -1, -1};
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
long long C(int a, int b) {
  if (b > a - b) b = a - b;
  long long res = 1;
  for (int i = 0; i < b; i++) res = res * (a - i) / (i + 1);
  return res;
}
long long unsigned power(long long N, long long R) {
  if (R == 0) return 1;
  long long unsigned p = (power(N, R / 2)) % mod;
  p = (p * p) % mod;
  if (R % 2) p = (p * N) % mod;
  return p;
}
bool prime(long long n) {
  if (n < 2) return false;
  for (int i = 2; i * i <= n; i++)
    if (!(n % i)) return false;
  return true;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int t{};
  cin >> t;
  while (t--) {
    int n{};
    cin >> n;
    vector<long long> v(n);
    long long od{}, ev{}, mx{}, mxx{-1000000000000}, ans{};
    for (int i = 0, sz = (int)n; i < sz; i++) {
      cin >> v[i];
      if (v[i] < 0) {
        od++;
        if (mxx < v[i]) mxx = v[i];
      } else {
        ev++;
        if (mx < v[i]) mx = v[i];
      }
    }
    int len{};
    if (!od)
      cout << mx << '\n';
    else if (!ev)
      cout << mxx << '\n';
    else {
      for (int i = 0, sz = (int)n; i < sz; i++) {
        mx = 0, mxx = -1000000000000;
        int j = i, f{}, ff{};
        if (v[i] < 0) {
          while (v[j] < 0 && j < n) {
            f = 1;
            if (v[j] < 0) {
              mxx = max(mxx, v[j]);
              j++;
            } else
              break;
          }
          if (f) ans += mxx;
        } else {
          while (v[j] > 0 && j < n) {
            ff = 1;
            if (v[j] > 0) {
              mx = max(mx, v[j]);
              j++;
            } else
              break;
          }
          if (ff) ans += mx;
        }
        i = j - 1;
      }
      cout << ans << '\n';
    }
  }
  return 0;
}
