IITKWPCA - Niceness of the string


The niceness of a string s (s comprises of a-z, A-Z and space characters only) is calculated using steps given below.

  1. First separate out the string into continuous non zero length string without space. eg. Let us take s = "now do it now". You can break this into four small strings as "now", "do", "it" and "now". Call the set of these small strings to be G.
  2. Now reverse all the strings in G. eg. "won", "od", "ti", "won".
  3. Finally you calculate number of distinct strings in you set. in this case answer is 3. as "won", "od" and "ti" are set of distinct strings. Note that "won" comes twice but counted only once.

So you have to find niceness value of a string s.

Note that given string s can contain more than one continuous spaces. eg. "now do it now ". Niceness value of this is also same as above given example.

Input

T: number of test cases. (T ≤ 100)

for next T lines, every line contains one string s (1 ≤ |s| ≤ 104)

Output

For every test case, output niceness value of given string s.

Example

Input:
4
now do it now
now      do it now
I am  good boy
am am

Output:
3
3
4
1

hide comments
rollicks_7: 2019-02-10 13:44:33

I am getting wrong answer on Judge3. I have already considered the case of only whitespaces.
But still WA. Please help!

pallav17: 2018-06-29 21:00:36

how to solve the problem....if there are multiple test cases and first test case is an empty srting it doesn't scan the first empty string.......im using c can anyone help with this one??

amulyagaur: 2017-07-30 20:52:35

wasted a lot of time debugging due to presence of empty spaces :(

vengatesh15: 2017-03-26 18:18:42

AC using getline(cin,s)

rohit9934: 2017-03-21 16:29:21

Learnt how to split strings using c++.

kira28: 2017-01-07 14:31:09

python :p

praval_singhal: 2016-06-28 21:32:26

Finally in Cpp With gets() :)

manas0008: 2016-02-03 12:34:33

Learnt stringstream.....!

Siddharth Singh: 2015-12-04 08:04:12

Set Function Python <3

jarvis: 2015-10-15 20:15:22

Ac IN PYthon !
can anyone give a hint to solve in c/c++
getting tle with sets!

Last edit: 2015-10-15 20:15:45

Added by:praveen123
Date:2013-08-05
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All
Resource:IITK ACA CSE online judge