#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long N = 1e5 + 5;
long long powm(long long a, long long b) {
  a %= mod;
  long long res = 1;
  while (b) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return res;
}
void sol() {
  int k = 2;
  string s;
  cin >> s;
  int n = ((long long)s.length());
  vector<pair<long long, long long>> arr(n);
  for (int i = 0; i < n; i++) {
    arr[i].first = s[i] - 'a' + 1;
    arr[i].second = i;
  }
  vector<long long> ans(n, 0);
  vector<long long> brr(k);
  sort(arr.begin(), arr.end());
  int j = 0;
  vector<pair<long long, long long>> va;
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (brr[j] == arr[i].first) continue;
    va.push_back({arr[i].second, j + 1});
    brr[j++] = arr[i].first;
    if (j == k) {
      while (((long long)va.size())) {
        ans[va.back().first] = va.back().second;
        va.pop_back();
      }
      j = 0;
      cnt++;
    }
  }
  cout << cnt << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    sol();
  }
}
