import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Random;

public class doall_password {
    private static final int MAX_ITERATION = 1000;
    private static final int MAX_LENGTH_OF_SUM = 10;

    String[][] HANDMADE = {
            {"1", "1"},
            {"12", "3"},
    };

    class Test {
        String from;
        String to;
        String comment;

        Test(String from, String to, String comment) {
            this.from = from;
            this.to = to;
            this.comment = comment;
        }


        @Override
        public String toString() {
            return from + " -> " + to;
        }

        public boolean solutionExists() {
            int pref = 0;
            while (pref < from.length() && pref < to.length() && from.charAt(pref) == to.charAt(pref)) {
                pref++;
            }
            int suf = 0;
            while (suf < from.length() && suf < to.length() && from.charAt(from.length() - 1 - suf) == to.charAt(to.length() - 1 - suf)) {
                suf++;
            }
            int len = to.length() - from.length();
            for (int left = 0; left < from.length(); left++) {
                for (int right = left + len; right <= Math.min(left + len + MAX_LENGTH_OF_SUM, from.length()); right++) {
                    boolean a = left <= pref;
                    boolean b = from.length() - right <= suf;

                    int toRight = to.length() - from.length() + right;

                    if (left > toRight) {
                        continue;
                    }
                    boolean c = sumOfDigit(from.substring(left, right)).equals(to.substring(left, toRight));

                    String got = from.substring(0, left) + sumOfDigit(from.substring(left, right)) + from.substring(right);
                    if (got.equals(to) != (a && b && c)) {
                        throw new AssertionError();
                    }
                    if (a && b && c) {
                        return true;
                    }

                }
            }
            return false;
        }
    }


    static String sumOfDigit(String s) {
        int x = 0;
        for (int i = 0; i < s.length(); i++) {
            x += s.charAt(i) - '0';
        }
        return "" + x;
    }

    static int sumOfDigitInteger(String s) {
        int x = 0;
        for (int i = 0; i < s.length(); i++) {
            x += s.charAt(i) - '0';
        }
        return x;
    }

    static String replaceWithSum(String s, int from, int to) {
        return s.substring(0, from) + sumOfDigit(s.substring(from, to)) + s.substring(to);
    }

    Random random = new Random(1);

    char randomDigit(boolean canZero) {
        if (canZero) {
            return (char) ('0' + random.nextInt(10));
        } else {
            return (char) ('1' + random.nextInt(9));
        }
    }

    String one_11111_Times() {
        return dup("1", 11111);
    }

    String makeNumberWithSumOfDigitStartingAndEndingAsThisNumber(String prefix, String suffix, String infix, int maxLength) {
        int target = Integer.parseInt(prefix + infix + suffix);
        ArrayList<Character> arrayList = new ArrayList<Character>();
        int sum = sumOfDigitInteger(prefix + suffix);

        while (sum <= target - 10) {
            char ch = randomDigit(true);
            sum += ch - '0';
            arrayList.add(ch);
        }
        if (target < sum) {
            throw new AssertionError();
        }
        arrayList.add((char) ('0' + (target - sum)));
        Collections.shuffle(arrayList, random);
        StringBuilder sb = new StringBuilder();
        sb.append(prefix);
        for (char c : arrayList) {
            sb.append(c);
        }
        sb.append(suffix);
        if (sb.length() > maxLength) {
            throw new AssertionError("Number is too long");
        }
        return sb.toString();
    }

    Test makeNiceTest1(int len, String innerPrefix, String innerSuffix, String middle) {
        String s = makeNumberWithSumOfDigitStartingAndEndingAsThisNumber(innerPrefix, innerSuffix, middle, len);
        int remain = len - s.length();
        int prefixLen = random.nextInt(remain);
        int suffixLen = remain - prefixLen;
        String prefix = randomString(prefixLen, false);
        String suffix = randomString(suffixLen, true);
        return new Test(prefix + s + suffix, prefix + sumOfDigit(s) + suffix, "Заменить центр на сумму, префикс и суффикс суммы совпадают с исходным числом");
    }

    Test makePureNiceTest1(int maxLen, String innerPrefix, String innerSuffix, String middle) {
        String s = makeNumberWithSumOfDigitStartingAndEndingAsThisNumber(innerPrefix, innerSuffix, middle, maxLen);
        return new Test(s, sumOfDigit(s), "Заменить всё число на сумму, префикс и суффикс суммы совпадают с исходным числом");
    }

    Test identityTest(int len) {
        String s = randomString(len);
        return new Test(s, s, "Оба числа совпадают");
    }

    String randomString(int len, boolean allowZeroOnFirstPosition) {
        StringBuilder sb = new StringBuilder();
        sb.append(randomDigit(allowZeroOnFirstPosition));
        for (int i = 1; i < len; i++) {
            sb.append(randomDigit(true));
        }
        return sb.toString();
    }

    String randomString(int len) {
        if (len < 0) {
            throw new AssertionError();
        }
        return randomString(len, false);
    }

    Test randomYesTest(int len) {
        String from = randomString(len);
        int left = random.nextInt(len - 1);
        int right = left + random.nextInt(len - left - 1) + 1;
        String to = replaceWithSum(from, left, right);
        return new Test(from, to, "Случайный тест");
    }

    Test randomYesTestWithZeroes(int len) {
        int leftLen = random.nextInt(len - 2);
        String left = randomString(leftLen);
        int rightLen = random.nextInt(len - leftLen - 2) + 1;
        String right = randomString(rightLen);
        String middle = randomString(len - leftLen - rightLen - 1);
        String from = left + "0" + middle + right;
        String to = left + "0" + sumOfDigit(middle) + right;
        return new Test(from, to, "Случайный тест, проверяет корректную обработку нулей");
    }

//    Test randomNoTest(int len) {
//        for (int i = 0; i < MAX_ITERATION; i++) {
//            String from = randomString(len);
//            String to = randomString(random.nextInt(len) + 1);
//            Test t = new Test(from, to);
//            if (!t.solutionExists()) {
//                return t;
//            }
//        }
//        throw new AssertionError("Can't find no test with len " + len);
//    }
//
//    Test hardNoTest1(int len) {
//        int prefixLen = (len / 4) + random.nextInt(len / 4 - 2);
//        int suffixLen = (len / 4) + random.nextInt(len / 4 - 2);
//        String prefix = randomString(prefixLen, false);
//        String suffix = randomString(suffixLen, true);
//        StringBuilder sb = new StringBuilder();
//        String sourceMiddle = dup("" + randomDigit(true), len - prefixLen - suffixLen);
//        String targetMiddle = sourceMiddle.substring(1);
//        return new Test(prefix + sourceMiddle + suffix, prefix + targetMiddle + suffix);
//    }

    Test all9(int len) {
        String from = dup("9", len);
        String to = sumOfDigit(from);
        return new Test(from, to, "Первое число 999...999, второе сумма всех цифр");
    }

    Test oneAndZeroes(int len) {
        String from = "1" + dup("0", len - 1);
        String to = sumOfDigit(from);
        return new Test(from, to, "Первое число 100...000, второе сумма всех цифр");
    }

    Test randomWithPrefixSum(int len, int prefixLength) {
        String from = randomString(len);
        String to = replaceWithSum(from, 0, prefixLength);
        return new Test(from, to, "Случайный тест, необходимо заменить префикс длины " + prefixLength + " на сумму");
    }

    Test randomWithSuffixSum(int len, int suffixLen) {
        String from = randomString(len);
        String to = replaceWithSum(from, len - suffixLen, len);
        return new Test(from, to, "Случайный тест, необходимо заменить суффикс длины " + suffixLen + " на сумму");
    }

    Test sumExceptFirstAndLast(int len, int first, int last) {
        String from = randomString(len);
        String to = replaceWithSum(from, first, len - last);
        return new Test(from, to, "Случайный тест, необходимо заменить все кроме первых " + first + " и последних " + last);
    }


    String dup(String s, int times) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < times; i++) {
            sb.append(s);
        }
        return sb.toString();
    }

    int fileNumber = 1;

    void write(Test test) {
        write(new File(String.format("%02d", fileNumber++)), test);
        comments.println(test.comment + ", длина первого числа = " + test.from.length() + ", длина второго числа = "  + test.to.length());
    }

    static void write(File file, Test test) {
        try {
            PrintWriter printWriter = new PrintWriter(file);
            printWriter.println(test.from);
            printWriter.println(test.to);
            printWriter.close();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    public final int MAXN1 = 9;
    public final int MAXN2 = 1000;
    public final int MAXN3 = (int) 1e5;
    PrintWriter comments;

    public void run() throws IOException {
        comments = new PrintWriter("tests.lst");
        /* Group 1, n <= 9 */
        for (String[] s : HANDMADE) {
            write(new Test(s[0], s[1], "из " + s[0] + " получить " + s[1]));
        }
        write(randomWithPrefixSum(MAXN1, 3));
        write(randomWithSuffixSum(MAXN1, 4));
        write(randomWithPrefixSum(MAXN1, MAXN1 - 1));
        write(randomWithSuffixSum(MAXN1, MAXN1 - 1));
        write(randomWithSuffixSum(MAXN1, 4));
        write(sumExceptFirstAndLast(MAXN1, 1, 1));
        write(randomYesTest(5));
        write(randomYesTest(MAXN1));
        write(randomYesTest(MAXN1));
        write(randomYesTest(MAXN1));
        write(identityTest(MAXN1));

        /* Group 2, n <= 1000 */
        write(new Test(dup("1", 11), "11", "11 единиц"));
        write(sumExceptFirstAndLast(MAXN2 - 1, random.nextInt(100), random.nextInt(100)));
        write(randomWithPrefixSum(MAXN2 - 2, MAXN2 / 3 + random.nextInt(MAXN2 / 3)));
        write(randomWithSuffixSum(MAXN2 - 3, MAXN2 / 3 + random.nextInt(MAXN2 / 3)));
        write(randomYesTest(MAXN2));
        write(randomYesTest(MAXN2));
        write(randomYesTest(MAXN2));
        write(randomYesTestWithZeroes(MAXN2 - 1));
        write(makeNiceTest1(MAXN2, "13", "59", ""));
        write(makePureNiceTest1(MAXN2, "23", "56", ""));
        write(all9(MAXN2));
        write(oneAndZeroes(MAXN2));
        write(identityTest(MAXN2));

        /* Group 3, n <= 10^6 */
        write(new Test(dup("1", 1112), "11111", "1112 единиц"));
        write(sumExceptFirstAndLast(MAXN3, random.nextInt(1000), random.nextInt(1000)));
        write(sumExceptFirstAndLast(MAXN3, random.nextInt(1000), random.nextInt(1000)));
        write(randomWithPrefixSum(MAXN3, MAXN3 / 3 + random.nextInt(MAXN3 / 3)));
        write(randomWithSuffixSum(MAXN3, MAXN3 / 3 + random.nextInt(MAXN3 / 3)));
        write(randomWithPrefixSum(MAXN3, MAXN3 - 1));
        write(randomWithSuffixSum(MAXN3, MAXN3 - 1));

        write(makeNiceTest1(MAXN3, "233", "566", ""));
        write(makePureNiceTest1(MAXN3, "239", "566", ""));
        write(makeNiceTest1(MAXN3, "17", "66", "32"));
        write(makeNiceTest1(MAXN3, "171", "", "2"));
        write(randomYesTest(MAXN3));
        write(randomYesTest(MAXN3));
        write(randomYesTest(MAXN3));
        write(randomYesTestWithZeroes(MAXN3 - 1));
        write(all9(MAXN3));
        write(oneAndZeroes(MAXN3));
        write(identityTest(MAXN3));
        comments.close();
    }

    public static void main(String[] args) throws IOException {
        new doall_password().run();
    }

}
