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 seperate out the string into continous 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 continous 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
Aayush: 2015-01-07 13:15:25

Python 3.4 : "internal error"
Python 2.7 AC

re(vamsi): PyPy and Python 3.4 are available only in Cube cluster
edit(vamsi): cluster is changed, now you can submit in Python 3.4

Last edit: 2015-02-03 16:30:26
NISHANT RAJ: 2014-11-06 19:49:36

take care of empty string (means only spaces)

Vamsi Krishna Avula: 2014-10-07 13:34:35

@eightnoteight, two lines :P

eightnoteight: 2014-09-04 16:57:51

AC in 3 lines of python

`Ak: 2014-08-18 09:17:20

[Link Removed]
i got runtime error(SIGSEGV)
pls help :(

re(vamsi): don't post your code/link to code here. use forum

Last edit: 2015-02-03 16:29:01
SUHAS E J: 2014-07-28 21:23:15

Easy in c++ using stringstream...
but in python, just 3 lines of code.. :P

Master_Mind: 2014-07-01 08:12:59

@praveen123
Getting wa.don't know why .please check my submission id 11861293

John and the cows: 2014-06-04 10:33:41

ahhh, I get NZEC again and again and again, don't know why :/

GURVINDER SINGH: 2014-06-02 20:34:25

STL rocks :P

Alexandre Henrique Afonso Campos: 2014-02-19 16:25:05

AC with one line code in python. Two to use libraries for fast IO, but I got WA. Apparently you must use the given number. To fix that, 3 lines.

Last edit: 2014-02-19 16:29:06

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