#include <algorithm>
using namespace std;

long long rnum, f[32] = {1};
int main() {
	for (int i = 1; i < 32; i++) // f[n] = sigma(C(n, i) * i!) = f[n-1] * n + 1;
		f[i] = f[i-1] * i + 1;
	char s[32], dictionary[32];
	int nextTest;
	scanf("%s", s);
	do {
		int n = strlen(s), used[26] = {};