#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    long long ans = 0;
    int cur = a[0];
    for (int i = 1; i < a.size(); i++) {
      if (a[i] * (long long)cur > 0) {
        cur = max(cur, a[i]);
      } else {
        ans += cur;
        cur = a[i];
      }
    }
    ans += cur;
    cout << ans << '\n';
  }
  return 0;
}
