This page is still under construction.

Parts of this page are still being built. What you see may change.

Numbers are Easy

Interview

Time limit1sMemory limit256 MB

Summary
Find the smallest positive multiple of N whose decimal digits are only 0 and 1 for each test case.
Level

Medium5 of 10

Topics
BFS, Graph, Number theory
Solved
No attempts yet

Problem

You are given an integer NN. Find the smallest positive integer XX that is divisible by NN and whose base 10 representation uses only the digits 0 and 1.

Input

The first line contains the number of test cases TT (1≤T≤1001 \le T \le 100).

Each of the next TT lines contains one integer NN (1≤N≤3001 \le N \le 300).

Output

For each test case, print on its own line the smallest positive integer XX that is divisible by NN and contains only the digits 0 and 1.

Under these constraints a solution always exists, and it fits in a signed 64 bit integer.

Examples3

  1. Example 1

    Input
    3
    1
    2
    20
    
    Expected output
    1
    10
    100
    
  2. Example 2

    Input
    5
    3
    7
    9
    11
    13
    
    Expected output
    111
    1001
    111111111
    11
    1001
    
  3. Example 3

    Input
    1
    1
    
    Expected output
    1