#include <bits/stdc++.h>
using namespace std;
int main() {
  int t = 1;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    long long sum = 0, p = 0, a[n];
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n - 1; i++) {
      int max = a[i], f = 1;
      while ((long long)a[i + 1] * (long long)a[i] > 0 && i != n - 1) {
        if (max < a[i + 1]) max = a[i + 1];
        i++;
        f = 0;
      }
      sum += max;
    }
    if ((long long)a[n - 1] * (long long)a[n - 2] < 0) sum += a[n - 1];
    cout << sum << endl;
  }
  return 0;
}
