#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
using namespace std;
bool isPowerOfTwo(long long int n) { return (ceil(log2(n)) == floor(log2(n))); }
void solve() {
  int n;
  cin >> n;
  long long int a[n];
  for (long long int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<vector<int>> v;
  long long int sum = 0, cur;
  for (long long int i = 0; i < n; i++) {
    if (a[i] < 0) {
      cur = a[i];
      while (a[i] < 0 && i < n) {
        cur = max(cur, a[i]);
        i++;
      }
    } else {
      while (a[i] > 0 && i < n) {
        cur = a[i];
        cur = max(cur, a[i]);
        i++;
      }
    }
    i--;
    sum = sum + cur;
  }
  cout << sum << endl;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  cerr << '\n'
       << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC
       << "ms\n";
  return 0;
}
