#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  int arr[n];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  if (n == 1) {
    cout << arr[0] << "\n";
    return;
  }
  int dp[n + 1];
  dp[0] = 1;
  int cnt = 0;
  long long int msum = LLONG_MIN;
  long long int sum = arr[0];
  for (int i = 1; i < n; i++) {
    if ((arr[i] ^ arr[i - 1]) < 0) {
      cnt++;
      sum += arr[i];
      dp[i] = max(cnt, dp[i - 1]);
    } else {
      if (cnt > dp[i - 1]) {
        msum = sum;
      }
      if (cnt == dp[i - 1]) {
        if (sum > msum) msum = sum;
      }
      cnt = 1;
      sum = arr[i];
      dp[i] = max(dp[i - 1], cnt);
    }
  }
  if (cnt > dp[n - 2]) msum = sum;
  if (cnt == dp[n - 2]) {
    if (sum > msum) msum = sum;
  }
  cout << msum << "\n";
}
int main() {
  int t;
  cin >> t;
  for (int i = 0; i < t; i++) solve();
  return 0;
}
