#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e6 + 1;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const long long int LINF = 1e18;
const long long int N = 100001;
void snake_bite() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout << fixed;
}
bool check(long long int x, long long int y) {
  if (x < 0 && y < 0 || x >= 0 && y >= 0) return true;
  return false;
}
void solve() {
  int n;
  cin >> n;
  vector<long long int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  int r;
  long long int sum = 0;
  for (int i = 0; i < n; i++) {
    long long int temp = a[i];
    r = i + 1;
    while (check(a[i], a[r]) && r < n) {
      if (a[r] > temp) temp = a[r];
      r++;
    }
    sum += temp;
    i = r - 1;
  }
  cout << sum;
}
int main() {
  snake_bite();
  long int t;
  cin >> t;
  while (t--) {
    solve();
    cout << endl;
  }
}
