#include <bits/stdc++.h>
using namespace std;
int s[200005], ans[200005];
int main() {
  int T;
  cin >> T;
  while (T--) {
    int n;
    scanf("%d", &n);
    int tot = 0;
    scanf("%d", &s[1]);
    ans[++tot] = s[1];
    for (int i = 2; i <= n; i++) {
      int p1, p2;
      scanf("%d", &s[i]);
      if (ans[tot] > 0)
        p1 = 1;
      else
        p1 = -1;
      if (s[i] > 0)
        p2 = 1;
      else
        p2 = -1;
      if (p1 == p2)
        ans[tot] = max(ans[tot], s[i]);
      else
        ans[++tot] = s[i];
    }
    long long int sum = 0;
    for (int i = 1; i <= tot; i++) sum += ans[i];
    printf("%I64d\n", sum);
  }
  return 0;
}
