#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e5 + 1;
const long long MOD = 1e9 + 7;
const long long INF = 1e9;
struct custom_hash {
  static uint64_t splitmix64(uint64_t x) {
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM =
        chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};
void output_vector(vector<long long>& v) {
  for (long long i = 0; i < v.size() - 1; i++) {
    cout << v[i] << " ";
  }
  cout << v.back() << "\n";
}
void solve() {
  string s;
  cin >> s;
  vector<long long> v(s.size());
  if (s[0] == '+')
    v[0] = 1;
  else
    v[0] = -1;
  long long mini = v[0];
  for (long long i = 1; i < s.size(); i++) {
    if (s[i] == '+') {
      v[i] = v[i - 1] + 1;
    } else {
      v[i] = v[i - 1] - 1;
    }
    mini = min(mini, v[i]);
  }
  unordered_map<long long, long long, custom_hash> umap;
  for (long long i = 0; i < v.size(); i++) {
    if (v[i] < 0) {
      if (umap[abs(v[i]) - 1] == 0) {
        umap[abs(v[i]) - 1] = i + 1;
      }
    }
  }
  long long ans = s.size();
  for (long long i = 0; i < abs(mini); i++) {
    ans += umap[i];
  }
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int tc = 1;
  cin >> tc;
  for (int t = 1; t <= tc; t++) {
    solve();
  }
}

### Prompt

Your task is to create a CPP solution to the following problem:

You are given a string s consisting only of characters + and -. You perform some process with this string. This process can be described by the following pseudocode: 
    
    
    res = 0  
    for init = 0 to inf  
        cur = init  
        ok = true  
        for i = 1 to |s|  
            res = res + 1  
            if s[i] == '+'  
                cur = cur + 1  
            else  
                cur = cur - 1  
            if cur < 0  
                ok = false  
                break  
        if ok  
            break  
    

Note that the inf denotes infinity, and the characters of the string are numbered from 1 to |s|.

You have to calculate the value of the res after the process ends.

Input

The first line contains one integer t (1 ≤ t ≤ 1000) — the number of test cases.

The only lines of each test case contains string s (1 ≤ |s| ≤ 10^6) consisting only of characters + and -.

It's guaranteed that sum of |s| over all test cases doesn't exceed 10^6.

Output

For each test case print one integer — the value of the res after the process ends.

Example

Input


3
--+-
---
++--+-


Output


7
9
6

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e5 + 1;
const long long MOD = 1e9 + 7;
const long long INF = 1e9;
struct custom_hash {
  static uint64_t splitmix64(uint64_t x) {
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM =
        chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};
void output_vector(vector<long long>& v) {
  for (long long i = 0; i < v.size() - 1; i++) {
    cout << v[i] << " ";
  }
  cout << v.back() << "\n";
}
void solve() {
  string s;
  cin >> s;
  vector<long long> v(s.size());
  if (s[0] == '+')
    v[0] = 1;
  else
    v[0] = -1;
  long long mini = v[0];
  for (long long i = 1; i < s.size(); i++) {
    if (s[i] == '+') {
      v[i] = v[i - 1] + 1;
    } else {
      v[i] = v[i - 1] - 1;
    }
    mini = min(mini, v[i]);
  }
  unordered_map<long long, long long, custom_hash> umap;
  for (long long i = 0; i < v.size(); i++) {
    if (v[i] < 0) {
      if (umap[abs(v[i]) - 1] == 0) {
        umap[abs(v[i]) - 1] = i + 1;
      }
    }
  }
  long long ans = s.size();
  for (long long i = 0; i < abs(mini); i++) {
    ans += umap[i];
  }
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int tc = 1;
  cin >> tc;
  for (int t = 1; t <= tc; t++) {
    solve();
  }
}

```