C - Fast Fouriest Transform 

Background

As everybody knows, every number can be transformed by means of using a different base to represent it. We say that, for a particular number, a transform is fourier than other if the first one uses the digit “4” more times than the second one. Also, a fouriest transform of a number is one that uses the digit “4” as many times as possible (i.e., there is no transform fourier than it).

The Problem

You have to write a program to find the smaller base that produces a fouriest transform for a number.

The Input

The input format is as follows:

An integer in a single line which says the number of problems to solve. Then, for each problem, a line with the integer number that has to be analyzed (smaller in absolute value than 1000000000).

The Output

The output for each problem consists of one line with three numbers separated by spaces: the analyzed number, the number of fours in a fouriest transform of that number, and the minimum base of the fouriest transform of the number.

If no transform can be found that uses the digit “4” to represent the number, then the output should be “X is infuriable.” (where X is the analyzed number).

Sample Input

4
4444
567
7895
7

Sample Output

4444 4 10
567 2 7
7895 1 5
7 is infuriable.

OMP'13
Facultad de Informatica
Universidad de Murcia (SPAIN)