Under construction

Still being built. Things may change

Awesome Numbers

Time limit0.5sMemory limit512 MB

Summary
Decide whether n is reachable from 1 by repeatedly applying P (nth prime) or S (nth perfect square), and print the shortest such sequence.
Level

Hard9 of 10

Topics
Number theory, Math
Solved
No attempts yet

Problem

As everyone knows, Kipa's favorite integer is 120. It has the following properties.

  • (ζ(−3))−1(\zeta(-3))^{-1}.
  • It is the first triperfect number.
  • It is the factorial of 5.
  • It is the 10th highly composite number.
  • It is the 15th triangular number.

The properties are listed in Kipa's order of preference.

Kipa also likes integer families, meaning subsets of the integers that satisfy some property. Kipa likes two families that are not on the list above: the primes and the perfect squares. So Kipa defined these operations:

  • P(n)P(n): the nnth prime.
  • S(n)S(n): the nnth perfect square.

For example, 5=P(P(P(1)))5 = P(P(P(1))) applies PP three times to 1, and 7=P(S(P(1)))7 = P(S(P(1))) applies PP, then SS, then PP. Kipa starts from 1 and repeatedly applies PP or SS. The integers reachable this way form the awesome numbers. Given a positive integer, decide whether it is an awesome number and make Kipa happy.

Input

The first line contains the number of test cases TT. TT is a positive integer at most 10510^5.

Each of the next TT lines contains a positive integer nn at most 101510^{15}.

Output

Print TT lines, similar to the sample output. For those who complained about the word "similar", the conditions are written below as regular expressions.

  • If nn is not an awesome number, print -1.
  • If nn is an awesome number, print the shortest string SS that satisfies all of the following conditions.
    • The regular expression ^1( [PS] [1-9][0-9]*)*$ accepts SS.
    • The regular expression ^.*n\$ accepts SS.
    • For any substring ss that has a non-digit character immediately before and after SS:
      • If the regular expression ^([0-9]+) P ([0-9]+)\$ accepts ss, then P({1}) = {2}` holds.
      • If the regular expression ^([0-9]+) S ([0-9]+)\$ accepts ss, then S({1}) = {2}` holds.

If nn is an awesome number, at least one string satisfying these conditions is guaranteed to exist. If several shortest SS exist, you may print any one of them.

Examples1

  1. Example 1

    Input
    10
    6
    7
    3
    5
    9
    1
    2
    8
    4
    3001
    
    Expected output
    -1
    1 P 2 S 4 P 7
    1 P 2 P 3
    1 P 2 P 3 P 5
    1 P 2 P 3 S 9
    1
    1 P 2
    -1
    1 P 2 S 4
    1 P 2 P 3 S 9 P 23 P 83 P 431 P 3001