#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int t, i;
  cin >> t;
  while (t--) {
    long long int n, mx = -1000000001, mx1 = 0, s = 0, flag;
    cin >> n;
    long long int a[n];
    for (i = 0; i < n; i++) {
      cin >> a[i];
    }
    if (n == 1) {
      cout << a[0] << "\n";
    } else if (n > 1) {
      for (i = 0; i < n; i++) {
        if (a[i] < 0) {
          if (flag == 0) {
            s = s + mx1;
          }
          flag = 1;
          mx1 = 0;
          mx = max(a[i], mx);
          if (i == n - 1) {
            s = s + mx;
          }
        } else if (a[i] > 0) {
          if (flag == 1) {
            s = s + mx;
          }
          mx = -1000000001;
          mx1 = max(a[i], mx1);
          flag = 0;
          if (i == n - 1) {
            s = s + mx1;
          }
        }
      }
      cout << s << "\n";
    }
  }
}
