#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];
  }
  long long int sum = 0, m;
  bool flag;
  for (long long int i = 0; i < n; i++) {
    if (i == 0 && a[i] < 0) {
      flag = false;
      m = a[i];
    } else if (i == 0 && a[i] > 0) {
      flag = true;
      m = a[i];
    } else if (a[i] > 0 && flag == false) {
      flag = true;
      sum = sum + m;
      m = a[i];
    } else if (a[i] < 0 && flag == true) {
      flag = false;
      sum = sum + m;
      m = a[i];
    }
    m = max(m, a[i]);
  }
  cout << sum + m << 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;
}
