#include <bits/stdc++.h>
using namespace std;
long long int fast(long long int n, long long int a, long long int m) {
  if (n == 0)
    return 1;
  else if (n == 1)
    return a;
  else {
    long long int r = fast(n / 2, a, m);
    if (n % 2 == 0) {
      return (((r % m) * (r % m)) % m);
    } else {
      return (((((r % m) * a) % m) * r) % m);
    }
  }
}
long long int ckck(long long int d) {
  long long int f = 0;
  while (d > 0) {
    f += (d % 2);
    d /= 2;
  }
  if (f == 1)
    return 1;
  else
    return 0;
}
int main() {
  int tt;
  cin >> tt;
  while (tt--) {
    long long int n, i;
    cin >> n;
    long long int A[n];
    for (i = 0; i < n; i++) {
      cin >> A[i];
    }
    long long int pos = 0, neg = 0;
    long long int Sum = 0, take = A[0];
    for (i = 1; i < n; i++) {
      if ((A[i] > 0 && A[i - 1] > 0) || (A[i] < 0 && A[i - 1] < 0)) {
        take = max(take, A[i]);
      } else {
        Sum += take;
        take = A[i];
      }
    }
    Sum += take;
    cout << Sum << "\n";
  }
}
