#include <bits/stdc++.h>
using namespace std;
int i;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, p = 0, mx = 0;
    vector<int> a;
    scanf("%d", &n);
    long long sum = 0;
    for (i = 0; i < n; i++) {
      scanf("%d", &p);
      a.push_back(p);
    }
    for (i = 0; i < n; i++) {
      vector<int> x;
      if (a[i] > 0) {
        while (a[i] > 0 && i < n) {
          x.push_back(a[i]);
          i++;
        }
        i--;
        sum += *max_element(x.begin(), x.end());
        x.clear();
      } else {
        while (a[i] < 0 && i < n) {
          x.push_back(a[i]);
          i++;
        }
        i--;
        sum += *max_element(x.begin(), x.end());
        x.clear();
      }
    }
    cout << sum << "\n";
  }
  return 0;
}
