#include <bits/stdc++.h>
using namespace std;
long long solve() {
  string s;
  cin >> s;
  long long res = 0;
  long long pos = 0;
  map<long long, long long> mp;
  for (long long i = 0; i < s.size(); i++) {
    if (s[i] == '+') {
      pos++;
    } else {
      pos--;
      if (pos < 0 && mp.find(pos) == mp.end()) {
        mp[pos] = 1;
        res += i + 1;
      }
    }
  }
  res += s.size();
  return res;
}
int main() {
  long long t;
  cin >> t;
  for (long long i = 0; i < t; i++) cout << solve() << endl;
}
