#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  long long ans, n, l, r;
  string s;
  cin >> t;
  while (t--) {
    cin >> s;
    n = s.size();
    ans = l = r = 0;
    for (int i = 0; i < n; i++) {
      if (s[i] == '-')
        r > 0 ? r-- : l++;
      else
        r++, l = 0;
      if (r < l) ans += (i + 1);
    }
    cout << ans + n << endl;
  }
  return 0;
}
