#include <bits/stdc++.h>
using namespace std;
struct mang {
  long long x, y;
};
bool ss1(mang c, mang v) { return (c.x < v.x); }
bool ss2(mang c, mang v) { return (c.y < v.y); }
bool ss3(mang c, mang v) { return (c.y > v.y); }
long long a[200005];
long long t, n, dem1, dem2, s1, s, i, tg, j, max1;
bool kt, kt2;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> t;
  while (t != 0) {
    cin >> n;
    s = 0;
    for (i = 1; i <= n; i++) cin >> a[i];
    if (n == 1)
      cout << a[1];
    else if (a[1] > 0) {
      i = 1;
      while (i <= n) {
        max1 = a[i];
        i++;
        while (a[i] > 0 && i <= n) {
          if (a[i] > max1) max1 = a[i];
          i++;
        }
        s += max1;
        if (i > n) break;
        max1 = a[i];
        i++;
        while (a[i] < 0 && i <= n) {
          if (a[i] > max1) max1 = a[i];
          i++;
        }
        s += max1;
      }
    } else {
      i = 1;
      while (i <= n) {
        max1 = a[i];
        i++;
        while (a[i] < 0 && i <= n) {
          if (a[i] > max1) max1 = a[i];
          i++;
        }
        s += max1;
        if (i > n) break;
        max1 = a[i];
        i++;
        while (a[i] > 0 && i <= n) {
          if (a[i] > max1) max1 = a[i];
          i++;
        }
        s += max1;
      }
    }
    cout << s << "\n";
    t--;
  }
}
