#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
long long mod2 = 123;
const long long N = 2e5 + 10;
const long long M = 1e6 + 5;
string s;
long long n, res;
void solve() {
  cin >> s;
  n = (long long)s.size();
  res = 0;
  int c = 0;
  map<int, int> m;
  for (int i = 0; i < n; i++) {
    if (s[i] == '+')
      c++;
    else
      c--;
    if (m.find(c) == m.end()) m[c] = i + 1;
  }
  for (int i = 0; i <= n + 1; i++) {
    if (m.find(-1 * i - 1) == m.end()) {
      res += n;
      break;
    } else
      res += m[-1 * i - 1];
  }
  cout << res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int t = 1;
  cin >> t;
  while (t--) {
    solve();
    cout << "\n";
  }
  return 0;
}
