#include <bits/stdc++.h>
using namespace std;
int num[200010];
int change[200010];
int main() {
  ios::sync_with_stdio(false);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    bool pos1, pos2;
    int mol = 1;
    change[1] = 1;
    for (int i = 1; i <= n; i++) {
      cin >> num[i];
      if (i != 1) {
        pos1 = num[i] > 0 ? true : false;
        pos2 = num[i - 1] > 0 ? true : false;
        if (pos1 != pos2) {
          mol++;
          change[mol] = i;
        }
      }
    }
    change[mol + 1] = n;
    long long sum = 0;
    for (int i = 1; i <= mol - 1; i++) {
      int tmp = num[change[i]];
      for (int j = change[i]; j <= change[i + 1] - 1; j++) {
        tmp = max(tmp, num[j]);
      }
      sum += tmp;
    }
    int tmp = num[change[mol]];
    for (int j = change[mol]; j <= n; j++) {
      tmp = max(tmp, num[j]);
    }
    sum += tmp;
    cout << sum << endl;
  }
  return 0;
}
