#include <bits/stdc++.h>
using namespace std;
long long int fast_pow(long long int k, long long int p) {
  if (p == 0) return 1;
  long long int P = fast_pow(k, p / 2);
  P = (P * P) % 1000000007;
  if (p % 2 == 1) P = (P * k) % 1000000007;
  return P;
}
long long int invmod(long long int a, long long int m) {
  return fast_pow(a, m - 2);
}
bool isPrime(long long int n) {
  if (n <= 1) return false;
  if (n <= 3) return true;
  if (n % 2 == 0 || n % 3 == 0) return false;
  for (int i = 5; i * i <= n; i = i + 6)
    if (n % i == 0 || n % (i + 2) == 0) return false;
  return true;
}
long long int nextPowerOf2(long long int n) {
  n >>= 1;
  long long int count = 0;
  if (n && !(n & (n - 1))) return n;
  while (n != 0) {
    n >>= 1;
    count += 1;
  }
  return 1 << count;
}
long long int binomialCoeff(long long int n, long long int k) {
  long long int C[k + 1];
  memset(C, 0, sizeof(C));
  C[0] = 1;
  for (long long int i = 1; i <= n; i++) {
    for (long long int j = min(i, k); j > 0; j--) C[j] = C[j] + C[j - 1];
  }
  return C[k];
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long int n;
    cin >> n;
    long long int a[n];
    for (long long int i = 0; i < n; i++) {
      cin >> a[i];
    }
    if (n == 1) {
      cout << a[0] << endl;
      continue;
    }
    long long int m = 0, msum = 0;
    long long int p;
    if (a[0] > 0)
      p = 0;
    else
      p = 1;
    vector<pair<long long int, long long int>> v1;
    long long int f = 0;
    long long int l = -1;
    long long int max = -1e9;
    long long int sum = 0;
    sum += a[0];
    long long int ans = -1e17;
    for (long long int i = 1; i < n; i++) {
      if (a[i] > 0 && p == 1) {
        l = i;
        p = 0;
        sum += a[i];
      } else if (a[i] < 0 && p == 0) {
        l = i;
        p = 1;
        sum += a[i];
      } else {
        long long int d = l - f;
        if (max <= d) {
          max = d;
          if (ans < sum) ans = sum;
        }
        f = i + 1;
        l = i + 1;
        sum = 0;
        sum += a[i];
      }
      if (i == n - 1) {
        long long int d = l - f;
        if (max <= d) {
          max = d;
          if (ans < sum) ans = sum;
        }
      }
    }
    cout << ans << endl;
  }
}
