#include <bits/stdc++.h>
using namespace std;
bool s(long long x) { return x > 0; }
int main() {
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    long long a[n];
    for (long long i = 0; i < n; i++) cin >> a[i];
    long long mx = 0, ans = 0;
    for (long long i = 0; i < n; i++) {
      long long j = i;
      mx = a[i];
      while (j < n && s(a[i]) == s(a[j])) {
        mx = max(mx, a[j]);
        j++;
      }
      i = j - 1;
      ans += mx;
    }
    cout << ans << endl;
  }
}
