#include <bits/stdc++.h>
using namespace std;
int i;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, p = 0, mx;
    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;) {
      if (a[i] > 0) {
        mx = a[i];
        while (a[i] > 0 && i < n) {
          mx = max(mx, a[i]);
          i++;
        }
        sum += mx;
      }
      if (a[i] < 0) {
        mx = a[i];
        while (a[i] < 0 && i < n) {
          mx = max(mx, a[i]);
          i++;
        }
        sum += mx;
      }
    }
    cout << sum << "\n";
  }
  return 0;
}
