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;
}

C. Get an Even String相关推荐

  1. Java知识——精华总结

    Java知识--精华总结 一.java概述与基础知识 1.何为编程? 编程就是让计算机为解决某个问题而使用某种程序设计语言编写程序代码,并最终得到结果的过程. 为了使计算机能够理解人的意图,人类就必须 ...

  2. mybatis查询报错:com.mysql.cj.exceptions.DataConversionException: Cannot determine value type from string

    mybatis查询报错: com.mysql.cj.exceptions.DataConversionException: Cannot determine value type from strin ...

  3. Go 学习笔记(60)— Go 第三方库之 go-redis(初始化 redis、操作 string、操作 list、操作 set、操作 hset)

    1. 第三方库 go-redis 因为 Go 标准库中是没提供 redis 的库,所以我们选择用 go-redis 这个第三方库.源码地址为 https://github.com/go-redis/r ...

  4. Redis 笔记(03)— string类型(设置key、获取key、设置过期时间、批量设置获取key、对key进行加减、对key值进行追加、获取value子串)

    字符串 string 是 Redis 最简单的数据结构.Redis 所有的数据结构都是以唯一的 key 字符串作为名称,然后通过这个唯一 key 值来获取相应的 value 数据.不同类型的数据结构的 ...

  5. python中的raw string的使用

    背景 我们经常需要使用raw string,在应用过程中,比如要使字符串中带一些转义字符或者其他的一些符号,我们就需要保持我们的字符成为raw string. 实例 输入 s = 'fadfafa\n ...

  6. Java中如何实现Date与String之间的数据类型转换

    String 数据类型转换成 Date String inputDate = "2021-04-11";Date outputDate = null;SimpleDateForma ...

  7. C++ string字符串的比较是否相等

    C++ string字符串的比较是否相等 可以使用compare 也可以使用"==" 1 使用比较运算符 == #include <iostream> #include ...

  8. python string 转bytes 以及bytes 转string

    string转 bytes 使用 encode str_a = "Python" str_bytes = str_a.encode() # encode默认编码方式是utf-8 所 ...

  9. TypeError: string argument without an encoding

    这个错误是把string 类型转byte类型的时候出现的问题 下面就会报错 print(bytes(str_a)) 修改为如下就好了 print(bytes(str_a.encode())) 或者就不 ...

  10. TypeError: ord() expected string of length 1, but int found

    错误如下 ord 里面要求的是一个string 的字符, 这里使用了int  ,所以修改了print(ord("1")) 转ASCII 的时候需要注意了,

最新文章

  1. 混合云计算应用中小企业市场前景看好
  2. 服务器管理器运行添加角色向导,Windows Server 2008 服务器角色的添加与管理
  3. springboot多数据源动态数据源(主从)
  4. SpringBoot中Bean按条件装配
  5. 中电海康建车联网透明路 探索新型智慧城市商机
  6. SpringBoot java串口操作(rxtx)
  7. mybatis入门1
  8. FTP服务器是什么意思?FTP服务器怎么搭建?
  9. IE11 For Win7、win2008中文版官方下载地址
  10. 口算训练java_java口算器
  11. 熊猫人表情包python 代码_Python实现表情包的代码实例
  12. emby,jellyfin,kodi系列
  13. 记账之后的收支明细,如何以收支图表的形式呈现
  14. 网络基础:(二)路由选择基础与静态路由
  15. HDU 1208 Pascal‘s Travels
  16. 花仙里云课堂知识付费v1.2.25知识付费 教育 直播
  17. ARM立即数的构成和有效立即数的判断
  18. 计算机上用户和组的意义,在域中管理用户和组
  19. XILINX FPGA数字信号处理——13、信号同步原理实现
  20. 有限补拓扑与Hausdorff空间与紧致空间

热门文章

  1. 顺序栈的基本操作(C++实现)
  2. 平板时代即将到来,写在即将发布Win8 Surface平板和iPad Mini之际
  3. matlab数字图像处理——图像的读写,灰度、二值图像
  4. Wall following algorithm机器人沿墙算法(一)
  5. 中学计算机教师人生职业规划,初中教师个人职业发展规划
  6. 一个清华差生10年奋斗经历
  7. JVM笔记-性能监控与分析工具
  8. ios 高德获取定位_更新日志-iOS 定位SDK | 高德地图API
  9. 单词 of 《cyberspace :if you don't love it ,leave it 》
  10. 53.大数据之旅——java分布式项目14-信息检索技术之Lucene,Solr