#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    long long a[n];
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    long long ans = 0;
    bool startSign = false;
    if (a[0] > 0) {
      startSign = true;
    }
    int i = 0;
    bool curr;
    if (startSign)
      curr = true;
    else
      curr = false;
    while (i < n) {
      if (curr) {
        long long num = INT_MIN;
        while (i < n && a[i] > 0) {
          num = max(num, a[i]);
          i++;
        }
        ans += num;
        curr = false;
      } else {
        long long num = INT_MIN;
        while (i < n && a[i] < 0) {
          num = max(num, a[i]);
          i++;
        }
        ans += num;
        curr = true;
      }
    }
    cout << ans << "\n";
  }
  return 0;
}
