#include <bits/stdc++.h>
using namespace std;
int sign(int x) { return (x > 0 ? 1 : -1); }
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  int t, n;
  cin >> t;
  while (t--) {
    cin >> n;
    int a[n + 5];
    long long sum = 0;
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 1; i <= n; i++) {
      int x = a[i];
      int j = i;
      while (j <= n && sign(a[i]) == sign(a[j])) {
        x = max(a[i], a[j]);
        j++;
      }
      i = j - 1;
      sum += x;
    }
    cout << sum;
    cout << "\n";
  }
  return 0;
}
