// Arup Guha
// Started on 3/20/2015, finished on 3/22/2015
// Solution to 2006 WF Problem D: Bipartite Numbers

// Note: This was accepted on ACM UVA's Site (http://uva.onlinejudge.org/)
//       Also, it's a bit of a hack - I noticed that the frequency of the right digit never
//       exceeds 200, so I limited my critical outer loop to this "magic" number. I don't
//       understand why the frequency of the right digit never gets so high.
//       This was also accepted on Live Archive, but without the "MAGIC" hack, with the loop
//       fully running its course.

import java.util.*;

public class bipartite {

	final public static int MAGIC = 200;

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);
		int n = stdin.nextInt();

		// Process each case.
		while (n != 0) {

			// mods[i][j] stores value of j i's in a row.
			int[][] mods = new int[10][Math.max(n/10,10)];

			// Inverse look up table - modBackwards[i][j] stores k,
			// where k is the smallest number of i's in a row equivalent to j mod n.
			int[][] modBackwards = new int[10][n];
			for (int i=0; i<10; i++)
				Arrays.fill(modBackwards[i], -1);

			// Go through each digit.
			for (int i=0; i<10; i++) {
				mods[i][0] = 0;
				for (int j=1; j<mods[0].length; j++) {

					mods[i][j] = (10*mods[i][j-1]+i)%n;

					if (modBackwards[i][mods[i][j]] == -1)
						modBackwards[i][mods[i][j]]  = j;
				}
			}

			// pow10[i] will store 10^i mod n.
			int[] pow10 = new int[Math.max(n/10,10)];
			pow10[0] = 1;
			for (int i=1; i<pow10.length; i++)
				pow10[i] = (10*pow10[i-1])%n;

			// Indicate no solution yet.
			num best = null;

			// Go through each number of digits on the right side, in increasing order.
			for (int right=1; right<=MAGIC; right++) {

				if (best != null && right >= best.totalDigits) break;

				// Loop over left digit, then right...
				for (int t=0; t<10; t++) {
					for (int s=1; s<10; s++) {

						if (s == t) continue;

						int cur = mods[t][right];

						// This is the necessary contribution of the left digit.
						int need = (n - cur)%n;
						int coeff = pow10[right]%n;

						boolean degenerate = false;
						if (coeff == 0) {
							if (need != 0) continue;
							degenerate = true;
						}

						// Degenerate solution.
						if (degenerate) {
							num tmp = new num(1, s, right, t);
							if (tmp.equals(n)) continue;
							// Update if necessary.
							if (best == null || tmp.compareTo(best) < 0) best = tmp;
							continue;
						}

						// This is because we need the gcd of 10^x (x=numRight) and our mod value.
						int myGCD = (int)(gcd(n, coeff));
						int newRHS = 0;

						// Easier case
						if (myGCD == 1) {
							int mult = modInv(n, coeff);
							newRHS = (int)(((long)need*mult)%n);
							if (modBackwards[s][newRHS] != -1) {
								num tmp = new num(modBackwards[s][newRHS], s, right, t);
								if (tmp.equals(n)) continue;
								if (best == null || tmp.compareTo(best) < 0) best = tmp;
							}
							continue;
						} // ends gcd = 1 case.

						// GCD not equal to 1
						else {

							// Can't have a solution, since LHS must always be 0 mod myGCD.
							if (need%myGCD != 0) continue;

							int newMod = n/myGCD;
							int newNeed = need/myGCD;
							int newCoeff = coeff/myGCD;
							int mult = modInv(newMod, newCoeff);

							// We solve equation with gcd 1...
							newRHS = (int)(((long)newNeed*mult)%newMod);

							// Then we must look at all valid mods, mod n, in our backwards
							// lookup table to see which one is the shortest frequency.
							int smallest = 10000000;
							for (int i=newRHS; i<n; i+=newMod)
								if (modBackwards[s][i] != -1 && modBackwards[s][i] < smallest)
									smallest = modBackwards[s][i];

							// Update if necessary.
							if (smallest < 10000000) {
								num tmp = new num(smallest, s, right, t);
								if (tmp.equals(n)) continue;
								if (best == null || tmp.compareTo(best) < 0) best = tmp;
							}
						}



					} // ends right loop
				} // ends s loop
			} // ends t loop

			// Here is our result.
			System.out.println(n+": "+best);

			// Get next case.
			n = stdin.nextInt();
		} // ends while n
	}

	public static long gcd(long a, long b) {
		if (b == 0) return a;
		if (a == 0) return b;
		return gcd(b, a%b);
	}

	// Pre-condition: gcd(a,b) = 1, a > b
	public static long[] myModInvRec(long a, long b) {

		// Base case.
		if (a%b == 0) {
			long[] ans = {0, 1, 1};
			return ans;
		}

		long[] recAns = myModInvRec(b, a%b);
		long[] ans = {recAns[1], recAns[0]-recAns[1]*(a/b), recAns[2]};
		return ans;
	}

	public static int modInv(int a, int b) {
		long[] res = myModInvRec(a, b);
		return res[1] >= 0 ? (int)res[1] :(int)(res[1]+a);
	}
}

class num implements Comparable<num> {

	public int numLeft;
	public int leftDigit;
	public int numRight;
	public int rightDigit;
	public int totalDigits;

	public num(int m, int s, int n, int t) {
		numLeft = m;
		leftDigit = s;
		numRight = n;
		rightDigit = t;
		totalDigits = numLeft + numRight;
	}

	// Returns true iff value equals this bipartite number.
	public boolean equals(int value) {
		int[] num = new int[totalDigits];
		for (int i=0; i<numRight; i++)
			num[i] = rightDigit;
		for (int i=numRight; i<totalDigits; i++)
			num[i] = leftDigit;
		for (int i=0; i<totalDigits; i++) {
			if (value%10 != num[i]) return false;
			value /= 10;
		}
		return value == 0;
	}

	public int compareTo(num other) {

		// Easy cases...
		if (this.totalDigits != other.totalDigits)
			return this.totalDigits - other.totalDigits;

		// Tie can be broken by most significant digit.
		if (this.leftDigit != other.leftDigit)
			return this.leftDigit - other.leftDigit;

		// First mismatch occurs when this switches digits.
		if (this.numLeft < other.numLeft)
			return this.rightDigit - other.leftDigit;

		// Here other switches digits first.
		if (other.numLeft < this.numLeft)
			return this.leftDigit - other.rightDigit;

		// Left digits match up perfectly, break the tie here.
		return this.rightDigit - other.rightDigit;
	}

	public String toString() {
		return numLeft+" "+leftDigit+" "+numRight+" "+rightDigit;
	}
}