#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000 * 1000 * 1000 + 7;
long long getRes(vector<long long> arr, long long n) {
  long long sum = 0;
  for (long long i = 0; i < n; ++i) {
    long long cur = arr[i];
    long long j = i;
    while (j < n && (arr[i]) * (arr[j]) > 0) {
      cur = max(cur, arr[j]);
      ++j;
    }
    sum += cur;
    i = j - 1;
  }
  return sum;
}
void solve() {
  long long n;
  cin >> n;
  vector<long long> arr(n);
  for (int i = 0; i < n; i++) cin >> arr[i];
  long long res = getRes(arr, n);
  cout << res << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
