#include <bits/stdc++.h>
using namespace std;
long long t, n, m;
int a[200003];
pair<int, int> p[200003];
int main() {
  cin >> t;
  while (t--) {
    cin >> n;
    for (int i = 1; i <= n; ++i) {
      cin >> a[i];
    }
    long long re = 0;
    for (int i = 1; i <= n;) {
      int val = a[i], j;
      for (j = i; j <= n && 1ll * a[j] * a[i] > 0; ++j) val = max(val, a[j]);
      re += val;
      i = j;
    }
    cout << re << "\n";
  }
  return 0;
}
