C. Get an Even String

A string a=a1a2…ana=a1a2…an is called even if it consists of a concatenation (joining) of strings of length 22 consisting of the same characters. In other words, a string aa is even if two conditions are satisfied at the same time:

  • its length nn is even;
  • for all odd ii (1≤i≤n−11≤i≤n−1), ai=ai+1ai=ai+1 is satisfied.

For example, the following strings are even: "" (empty string), "tt", "aabb", "oooo", and "ttrrrroouuuuuuuukk". The following strings are not even: "aaa", "abab" and "abba".

Given a string ss consisting of lowercase Latin letters. Find the minimum number of characters to remove from the string ss to make it even. The deleted characters do not have to be consecutive.

Input

The first line of input data contains an integer tt (1≤t≤1041≤t≤104) —the number of test cases in the test.

The descriptions of the test cases follow.

Each test case consists of one string ss (1≤|s|≤2⋅1051≤|s|≤2⋅105), where |s||s| — the length of the string ss. The string consists of lowercase Latin letters.

It is guaranteed that the sum of |s||s| on all test cases does not exceed 2⋅1052⋅105.

Output

For each test case, print a single number — the minimum number of characters that must be removed to make ss even.

Example

input

Copy

6
aabbdabdccc
zyx
aaababbb
aabbcc
oaoaaaoo
bmefbmuyw

output

Copy

3
3
2
0
2
7

Note

In the first test case you can remove the characters with indices 66, 77, and 99 to get an even string "aabbddcc".

In the second test case, each character occurs exactly once, so in order to get an even string, you must remove all characters from the string.

In the third test case, you can get an even string "aaaabb" by removing, for example, 44-th and 66-th characters, or a string "aabbbb" by removing the 55-th character and any of the first three.

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<map>
using namespace std;


void sove(){
	char s[200005];
	scanf("%s",s);
	int ans=0;
	map<char,int> mp;
	int n=strlen(s);
	bool f=true;
	for(int i=0;i<n;i++){
		if(f){
			f=false;
			mp.clear();
			mp[s[i]]++;
		}else{
			if(mp[s[i]]){
				f=true;
			}else{
				ans++;
				mp[s[i]]++;
			}
		}
	}
	if((n-ans)%2!=0){
		ans++;
	}
	printf("%d\n",ans);
}
int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		sove();
	}
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值