#include <bits/stdc++.h>
using namespace std;
int64_t gcd(int64_t n, int64_t m) { return m ? gcd(m, n % m) : n; }
int64_t lcm(int64_t n, int64_t m) { return n / gcd(n, m) * m; }
struct debugger {
  static void call(string::iterator it, string::iterator ed) {}
  template <typename T, typename... aT>
  static void call(string::iterator it, string::iterator ed, T a, aT... rest) {
    string b;
    for (; *it != ','; ++it)
      if (*it != ' ') b += *it;
    cout << b << "=" << a << " ";
    call(++it, ed, rest...);
  }
};
void input() {
  freopen("input.txt", "r", stdin);
  ;
  freopen("output.txt", "w", stdout);
  ;
}
void solve() {
  int64_t n;
  scanf("%lld", &n);
  ;
  int64_t arr[n];
  for (int64_t i = 0; i < n; i++) {
    scanf("%lld", &arr[i]);
    ;
  }
  int64_t parity = 0, ans = 0;
  for (int64_t i = 0; i < n; i++) {
    int64_t mx = INT_MIN;
    if (arr[i] > 0) {
      parity = 1;
    } else {
      parity = 0;
    }
    if (parity) {
      while (i < n && arr[i] > 0) {
        mx = max(mx, arr[i]);
        i++;
      }
      ans += mx;
      i--;
    } else {
      while (i < n && arr[i] < 0) {
        mx = max(mx, arr[i]);
        i++;
      }
      ans += mx;
      i--;
    }
  }
  cout << ans << '\n';
}
int32_t main() {
  int64_t tt;
  int64_t Case = 0;
  cin >> tt;
  while (tt--) {
    solve();
  }
  return 0;
}
