#include <bits/stdc++.h>
using namespace std;
int i, j, k;
int main() {
  std::ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    ;
    k = 0;
    bool ok;
    long long int res = 0, cur;
    vector<int> v;
    int pre = 0;
    for (i = 0; i < s.size(); i++) {
      if (s[i] == '-' and pre == 0) {
        res += i + 1;
      } else if (s[i] == '+') {
        pre++;
      } else
        pre--;
    }
    res += s.size();
    cout << res << "\n";
  }
}
