#include <bits/stdc++.h>
using namespace std;
const int maxSize = 2 * 10e5 + 1;
long long a[maxSize];
void f(int size) {
  long long sum = -1 * (1e15 + 1), sum2 = a[0];
  for (int i = 1; i < size; i++) {
    if ((a[i] > 0 && a[i - 1] < 0) || (a[i] < 0 && a[i - 1] > 0)) {
      sum2 += a[i];
    } else {
      sum = (sum > sum2) ? sum : sum2;
      sum2 = a[i];
    }
  }
  sum = (sum > sum2) ? sum : sum2;
  cout << sum << endl;
}
int main() {
  int t, size;
  long long n;
  cin >> t;
  while (t--) {
    cin >> size;
    for (int i = 0; i < size; i++) {
      cin >> n;
      a[i] = n;
    }
    f(size);
  }
  return 0;
}
