#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long int lcm(long long int a, long long int b) {
  return (a * b) / gcd(a, b);
}
long long int modi(long long int n, long long int m = 1000000007) {
  n %= m;
  n += m;
  n %= m;
  return n;
}
const long long int INF = 1e18 + 999999999999999999;
const long long int N = 2e5 + 5;
const long double pi = 4 * atan(1);
long long int n, m, k, t;
long long int p, q, l, r;
long long int arr[N];
long long int a, b, c, d;
long long int x[1000005], y[1000005];
map<long long int, long long int> m1, m2;
vector<long long int> v, v1, v2;
long long int pre[N], suff[N];
char grid[11][11];
vector<pair<long long int, long long int>> pl;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int i = 0, j = 0;
  long long int t;
  cin >> t;
  long long int cno = 0;
  while (t--) {
    cin >> n;
    v.clear();
    for (long long int i = 0; i < n; i++) cin >> a, v.push_back(a);
    i = 0, j = 0;
    long long int ans = 0;
    long long int cur = 0;
    while (i < n) {
      if (v[i] > 0) {
        j = i;
        long long int cur = v[i];
        while (j < n && v[j] > 0) {
          cur = max(cur, v[j]);
          j++;
        }
        i = j;
        ans += cur;
      } else {
        j = i;
        long long int cur = v[i];
        while (j < n && v[j] < 0) {
          cur = max(cur, v[j]);
          j++;
        }
        i = j;
        ans += cur;
      }
    }
    cout << ans << '\n';
  }
}
