#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200010;
int test, n;
long long int v[MAXN];
void solve() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%lld", &v[i]);
  v[n + 1] = 0;
  long long int ans = 0, mx = 0;
  for (int i = 1; i <= n + 1; i++) {
    if (v[i] * v[i - 1] > 0)
      mx = max(v[i], mx);
    else
      ans += mx, mx = v[i];
  }
  printf("%lld\n", ans);
}
int main() {
  scanf("%d", &test);
  while (test--) solve();
}
