1. 

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.Collection;
import java.util.HashMap;
import java.util.StringTokenizer;

/**
* Angewandte Mathematik, SS09, IFB 2C
* ACM Problem #10338 (Mischievous Children)
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=15&page=show_problem&problem=1279
*
* @author Christian Posselt
* @author Jonathan Schubert
*
* Idee aus der Vorlesung Diskrete Mathematik Beispiel 5 Permutationen(Anordnungen)
*
* @version 1.0, 06/08/2009
*
* Bases Formula
*
* Amount of Permutations = WordLength! / All the multiple letters!
*
* Bsp: MISSISSIPPI = 11!/(4!*4!*2!)
*
*
* Status : Accepted
* Runtime: 1.796
*/

class MischievousChildren
{
public static void main(String... args) throws IOException
{
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
StringBuilder bu = new StringBuilder();
int index = 1;
for(int cases = Integer.parseInt(reader.readLine());cases > 0; cases --)
{
String line = reader.readLine();
StringTokenizer tokenizer = new StringTokenizer(line);
while(tokenizer.hasMoreTokens())
{
bu.append("Data set "+index+": ");
bu.append(countPermutations(tokenizer.nextToken()).toString()+"\n");
index ++;
}
}
bu.deleteCharAt(bu.length()-1);
System.out.println(bu.toString());
}

public static BigInteger countPermutations(String userInput)
{
HashMap<Character,BigInteger> chars = new HashMap<Character,BigInteger>();
//HashMap contains amount and factorial of amount for each character in word, coded in this way!
//factorial n Digits. Last two Digits contains amount. Bsp. 101 means current factorial 1, amount 1 and so on
BigInteger fak = new BigInteger("1");
//run through all characters
for(BigInteger index = new BigInteger("0"); index.intValue() < userInput.length(); index = index.add(BigInteger.ONE))
{
int indexInt = index.intValue();
fak = fak.multiply(index.add(BigInteger.ONE));
char key = userInput.charAt(indexInt);
//put them to map
if(chars.containsKey(key))
{
//map knows character
BigInteger code = chars.get(key);
BigInteger amount = code.mod(BigInteger.TEN.multiply(BigInteger.TEN));
BigInteger numberfak = code.divide(BigInteger.TEN.multiply(BigInteger.TEN));
amount = amount.add(BigInteger.ONE);
numberfak = numberfak.multiply(amount);
//calculate next factorial(newFactorial = oldFactorial*(amountlast+1)) and increment amount. After this create new code and save it in map
chars.put(key, numberfak.multiply(BigInteger.TEN).multiply(BigInteger.TEN).add(amount));
}
else
chars.put(key, new BigInteger("101"));
}
Collection<BigInteger> keys = chars.values();
BigInteger denominator = new BigInteger("1");
//calculate the denominator
//This are the double Letters in Word. Changing them is no Permutation!
for(BigInteger amount: keys)
denominator = denominator.multiply(amount.divide(BigInteger.TEN.multiply(BigInteger.TEN)));

return(fak.divide(denominator));
}
}