#include <bits/stdc++.h>
const int MOD = 998244353;
const int N = 1e6;
const int mod = 1e9 + 7;
using namespace std;
int t, i, j, n, x;
int a[N];
int pos, neg, maxx;
void solve() {
  cin >> n;
  pos = 0;
  neg = 0;
  maxx = INT_MIN;
  for (int i = (0); i < (n); ++i) cin >> a[i];
  for (int i = (0); i < (n); ++i) {
    if (a[i] > 0)
      pos++;
    else
      neg++;
    if (a[i] - maxx > 0) maxx = a[i];
  }
  if (pos == 0 || neg == 0)
    cout << maxx << "\n";
  else {
    int ch = 0;
    if (a[0] > 0)
      ch = 1;
    else
      ch = -1;
    long long int ans = 0;
    i = 0;
    while (i < n) {
      int temp = -1000000001;
      if (ch == 1) {
        while (a[i] > 0 && i < n) {
          if (a[i] > temp) temp = a[i];
          i++;
        }
        ch = 0;
        ch--;
      } else {
        while (a[i] < 0 && i - n < 0) {
          if (a[i] - temp > 0) temp = a[i];
          i++;
        }
        ch = 0;
        ch++;
      }
      ans += temp;
    }
    cout << ans << "\n";
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
