1379 and Cubes

Time limit1sMemory limit128 MB

Summary
Given a number S ending in 1,3,7 or 9 with up to 10 digits, find any integer x (no longer than S) whose cube's last digits exactly match S.
Level

Medium6 of 10

Topics
Number theory, Math, Brute force
Solved
No attempts yet

Problem

You are given a number S. The last digit of S is one of 1, 3, 7, and 9. For every such S, there is always an integer x whose cube ends with S.

For each test case, find and print any integer x such that the ending digits of x^3 are exactly S, and the decimal length of x is at most the decimal length of S.

Input

The first line contains the number of test cases T.

Each of the next T lines contains one number S. The number S ends in one of 1, 3, 7, and 9, and has at most 10 digits.

Output

For each test case, print one integer x satisfying the condition, one per line.

Examples1

  1. Example 1

    Input
    4
    123
    1234567
    435621
    9876543213
    Expected output
    947
    2835223
    786941
    2916344917