using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Numerics;

namespace ProblemSolving
{
    class Program
    {
        static void Main(string[] args)
        {
            string m = Console.ReadLine();
            int rounds = Convert.ToInt16(m);
            int[] outputs = new int[2 * rounds];
            int[] tries = new int[2];
            for (int i = 0; i < rounds; i+=2)
            {
                string m1 = Console.ReadLine();
                toint(m1,ref tries);
                outputs[i] = tries[0];
                outputs[i + 1] = tries[1];
            }
            //even numbers for Mishaka & odd for Chris
            int Mwin = 0, Cwin= 0;
            for (int i = 0; i < rounds; i+=2)
            {
                if (outputs[i] > outputs[i + 1])
                    Mwin++;
                else if (outputs[i + 1] > outputs[i])
                    Cwin++;
            }
            if (Mwin > Cwin)
                Console.WriteLine("Mishka");
            else if (Cwin > Mwin)
                Console.WriteLine("Chris");
            else if (Cwin == Mwin)
                Console.WriteLine("Friendship is magic!^^");

        }
        public static void toint(string m1, ref int[] i1)
        {
            StringBuilder in1 = new StringBuilder();
            int i = 0;
            int counter = 0;
            foreach (char c in m1)
            {

                if ((c >= '0' && c <= '9'))
                {
                    in1.Append(c);
                }
                else if (c == ' ')
                {
                    if (i1[counter] == 0)
                    {
                        string m = in1.ToString();
                        i1[counter] = Convert.ToInt32(m);
                        counter++;
                        in1.Clear();
                    }

                }
                else break;
                i++;
                if (i == m1.Length)
                {
                    string m = in1.ToString();
                    i1[counter] = Convert.ToInt32(m);
                    in1.Clear();
                    break;
                }

            }
        }
    }
}


using System;
using System.IO;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;

class Program
{

    //////////////////////////////////////////////////
    void Solution()
    {
        var n = ri;
        int suma = 0;
        int sumb = 0;
        for (int i = 0; i < n; i++)
        {
            var a = ri;
            var b = ri;
            if (a > b)
                suma++;
            if (a < b)
                sumb++;

        }

        if (suma > sumb)
        {
            wln("Mishka");
        }
        else if (suma < sumb)
        {
            wln("Chris");
        }
        else
        {
            wln("Friendship is magic!^^");
        }

    }
    //////////////////////////////////////////////////

    static void swap<T>(ref T o1, ref T o2) { var o = o1; o1 = o2; o2 = o; }
    static void wln(object o = null) { Console.WriteLine(o); }
    static void wsp(object o) { Console.Write(o + " "); }
    static void wrt(object o) { Console.Write(o); }

    //Console.Write(string.Format(CultureInfo.InvariantCulture, "{0:F12}", o));

    static long gcd(long a, long b) { return (b != 0) ? gcd(b, a % b) : a; }
    static long lcm(long a, long b) { return a / gcd(a, b) * b; }

    int ri
    {
        get
        {
            _read(); while (_str[_ind] == ' ') ++_ind;
            int sign = 1; if (_str[_ind] == '-') { sign = -1; ++_ind; }
            int p = 0;
            while (_ind < _count && _str[_ind] != ' ') p = p * 10 + _str[_ind++] - '0';
            while (_ind < _count && _str[_ind] == ' ') ++_ind; return p * sign;
        }
    }
    long rl
    {
        get
        {
            _read(); while (_str[_ind] == ' ') ++_ind;
            int sign = 1; if (_str[_ind] == '-') { sign = -1; ++_ind; }
            long p = 0;
            while (_ind < _count && _str[_ind] != ' ') p = p * 10 + _str[_ind++] - '0';
            while (_ind < _count && _str[_ind] == ' ') ++_ind; return p * sign;
        }
    }
    double rd
    {
        get
        {
            _read(); while (_str[_ind] == ' ') ++_ind; int sign = 1; if (_str[_ind] == '-') { sign = -1; ++_ind; }
            long p = 0, q = 1; while (_ind < _count && _str[_ind] != ' ' && _str[_ind] != '.') p = p * 10 + _str[_ind++] - '0';
            if (_ind < _count && _str[_ind] == '.') { ++_ind; while (_ind < _count && _str[_ind] != ' ') { p = p * 10 + _str[_ind++] - '0'; q *= 10; } }
            while (_ind < _count && _str[_ind] == ' ') ++_ind; return (double)p / q * sign;
        }
    }
    string rs
    {
        get
        {
            _read(); while (_ind < _count && _str[_ind] == ' ') ++_ind;
            var tmp = _str.IndexOf(' ', _ind);
            if (tmp == -1) { _count = 0; _ind = 0; return _str.Substring(_ind); }
            var s = _str.Substring(_ind, tmp - _ind); _ind = tmp + 1;
            while (_ind < _count && _str[_ind] == ' ') ++_ind; return s;
        }
    }

    int[] ria(int n)
    {
        var res = new int[n];
        for (int k = 0; k < n;)
        {
            var s = Console.ReadLine(); var m = s.Length;
            for (int i = 0; i < m && k < n; ++i)
            {
                while (i < m && s[i] == ' ') ++i; if (i == m) break; int sign = 1; if (s[i] == '-') { sign = -1; ++i; }
                int p = 0; while (i < m && s[i] != ' ') p = p * 10 + s[i++] - '0'; res[k++] = p * sign;
            }
        }
        _count = 0; _ind = 0; return res;
    }
    long[] rla(int n)
    {
        var res = new long[n];
        for (int k = 0; k < n;)
        {
            var s = Console.ReadLine(); var m = s.Length;
            for (int i = 0; i < m && k < n; ++i)
            {
                while (i < m && s[i] == ' ') ++i; if (i == m) break; int sign = 1; if (s[i] == '-') { sign = -1; ++i; }
                long p = 0; while (i < m && s[i] != ' ') p = p * 10 + s[i++] - '0'; res[k++] = p * sign;
            }
        }
        _count = 0; _ind = 0; return res;
    }
    double[] rda(int n)
    {
        var res = new double[n];
        for (int k = 0; k < n;)
        {
            var s = Console.ReadLine(); var m = s.Length;
            for (int i = 0; i < m && k < n; ++i)
            {
                while (i < m && s[i] == ' ') ++i; if (i == m) break; int sign = 1; if (s[i] == '-') { sign = -1; ++i; }
                long p = 0, q = 1; while (i < m && s[i] != ' ' && s[i] != '.') p = p * 10 + s[i++] - '0';
                if (i < m && s[i] == '.') { ++i; while (i < m && s[i] != ' ') { p = p * 10 + s[i++] - '0'; q *= 10; } }
                res[k++] = (double)p / q * sign;
            }
        }
        _count = 0; _ind = 0; return res;
    }
    string[] rsa(int n) { var res = new string[n]; for (int k = 0; k < n; ++k) res[k] = Console.ReadLine(); _count = 0; _ind = 0; return res; }
    string _str = null; int _count = 0; int _ind = 0;
    void _read() { if (_ind == _count) { _str = Console.ReadLine(); _count = _str.Length; _ind = 0; } }
    static void Main() { new Program().Solution(); }
}


using System;

namespace _703A
{
    class Program
    {
        static void Main()
        {
            var n = int.Parse(Console.ReadLine());
            int first = 0;
            int second = 0;
            for (int i = 0; i < n; i++)
            {
                var res = Console.ReadLine().Split();
                var Mishka = int.Parse(res[0]);
                var Chris = int.Parse(res[1]);
                if (Mishka > Chris) first++;
                else if (Chris > Mishka) second++;
            }
            if (first > second) Console.WriteLine("Mishka");
            else if (second > first) Console.WriteLine("Chris");
            else Console.WriteLine("Friendship is magic!^^");
        }
    }
}


using System;
using System.Collections.Generic;
using System.Text;

namespace CodeForces
{
    class Program
    {
        static readonly long MOD = (long)Math.Pow(10, 9) + 7;

        public static int re(string s)
        {
            return Int32.Parse(s);
        }

        static void Main(string[] args)
        {
            int n = re(Console.ReadLine());
            /*string[] io = Console.ReadLine().Split(' ');
            int n = re(io[0]);
            int m = re(io[1]);*/

            int a = 0;
            int b = 0;
            for (int i = 0; i < n; i++)
            {
                string[] io = Console.ReadLine().Split(' ');
                int x = re(io[0]);
                int y = re(io[1]);
                if (x > y)
                    a++;
                else if (y > x)
                    b++;
            }

            if (a > b)
                Console.WriteLine("Mishka");
            else if (b > a)
                Console.WriteLine("Chris");
            else
                Console.WriteLine("Friendship is magic!^^");

            //Console.ReadLine();

        }
    }
}


using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Linq;
using System.Globalization;

class Program
{
    static void Main(string[] args)
    {
        var n = RI();
        //var m = RIA(n);

        long a1 = 0;
        long a2 = 0;
        long a3 = 0;
        for (int i = 0; i < n; i++)
        {
            int a = RI();
            int b = RI();
            if (a == b) a1++;
            if (a < b) a2++;
            if (a > b) a3++;
        }

        if (a3 > a2) Console.WriteLine("Mishka");
        if (a3 < a2) Console.WriteLine("Chris");
        if (a3 == a2) Console.WriteLine("Friendship is magic!^^");

    }

    private static int GCD(int a, int b)
    {
        if (a % b == 0) return b;
        return GCD(b, a % b);
    }

    private static int Mod = 1000000007;
    private static List<int>[] ReadGraph(int n, int m)
    {
        List<int>[] g = new List<int>[n];
        for (int i = 0; i < n; i++) g[i] = new List<int>();
        for (int i = 0; i < m; i++)
        {
            int a = RI() - 1;
            int b = RI() - 1;

            g[a].Add(b);
            g[b].Add(a);
        }

        return g;
    }

    private static int[,] ReadGraphAsMatrix(int n, int m)
    {
        int[,] matrix = new int[n + 1, n + 1];
        for (int i = 0; i < m; i++)
        {
            int a = RI();
            int b = RI();
            matrix[a, b] = matrix[b, a] = 1;
        }

        return matrix;
    }

    private static void Sort(ref int a, ref int b)
    {
        if (a > b) Swap(ref a, ref b);
    }

    private static void Swap(ref int a, ref int b)
    {
        int tmp = a;
        a = b;
        b = tmp;
    }

    private const int BufferSize = 1 << 12;
    private static StreamReader consoleReader;
#if TOLYAN_TEST
    private static MemoryStream testData;
#endif

    private static int RI()
    {
        int ans = 0;
        int mul = 1;
        do
        {
            ans = consoleReader.Read();
            if (ans == -1)
                return 0;
            if (ans == '-') mul = -1;
        } while (ans < '0' || ans > '9');

        ans -= '0';
        while (true)
        {
            int chr = consoleReader.Read();
            if (chr < '0' || chr > '9')
                return ans * mul;
            ans = ans * 10 + chr - '0';
        }
    }

    private static ulong RUL()
    {
        ulong ans = 0;
        int chr;
        do
        {
            chr = consoleReader.Read();
            if (chr == -1)
                return 0;
        } while (chr < '0' || chr > '9');

        ans = (uint)(chr - '0');
        while (true)
        {
            chr = consoleReader.Read();
            if (chr < '0' || chr > '9')
                return ans;
            ans = ans * 10 + (uint)(chr - '0');
        }
    }

    private static long RL()
    {
        long ans = 0;
        int mul = 1;
        do
        {
            ans = consoleReader.Read();
            if (ans == -1)
                return 0;
            if (ans == '-') mul = -1;
        } while (ans < '0' || ans > '9');

        ans -= '0';
        while (true)
        {
            int chr = consoleReader.Read();
            if (chr < '0' || chr > '9')
                return ans * mul;
            ans = ans * 10 + chr - '0';
        }
    }

    private static int[] RIA(int n)
    {
        int[] ans = new int[n];
        for (int i = 0; i < n; i++)
            ans[i] = RI();
        return ans;
    }

    private static long[] RLA(int n)
    {
        long[] ans = new long[n];
        for (int i = 0; i < n; i++)
            ans[i] = RL();
        return ans;
    }

    private static char[] ReadString()
    {
        int ans;

        do
        {
            ans = consoleReader.Read();
        } while (!((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z')));

        List<char> s = new List<char>();
        do
        {
            s.Add((char)ans);
            ans = consoleReader.Read();
        } while ((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z'));

        return s.ToArray();
    }

    private static char[] ReadString(int n)
    {
        int ans;

        do
        {
            ans = consoleReader.Read();
        } while (!((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z')));

        char[] s = new char[n];
        int pos = 0;
        do
        {
            s[pos++] = (char)ans;
            if (pos == n) break;
            ans = consoleReader.Read();
        } while ((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z'));

        return s;
    }

    private static char ReadLetter()
    {
        while (true)
        {
            int ans = consoleReader.Read();
            if ((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z'))
                return (char)ans;
        }
    }
    private static char ReadNonLetter()
    {
        while (true)
        {
            int ans = consoleReader.Read();
            if (!((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z')))
                return (char)ans;
        }
    }

    private static char ReadDigit()
    {
        while (true)
        {
            int ans = consoleReader.Read();
            if (ans >= '0' && ans <= '9')
                return (char)ans;
        }
    }

    private static int ReadDigitInt()
    {
        return ReadDigit() - (int)'0';
    }

    private static char ReadAnyChar()
    {
        return (char)consoleReader.Read();
    }

    private static string DoubleToString(double x)
    {
        return x.ToString(CultureInfo.InvariantCulture);
    }

    private static double DoubleFromString(string x)
    {
        return double.Parse(x, CultureInfo.InvariantCulture);
    }

    static Program()
    {
        //Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
        consoleReader = new StreamReader(Console.OpenStandardInput(BufferSize), Encoding.ASCII, false, BufferSize);
    }

    private static void PushTestData(string data)
    {
#if TOLYAN_TEST
        if (testData == null)
        {
            testData = new MemoryStream();
            consoleReader = new StreamReader(testData);
        }

        var pos = testData.Position;
        var bytes = Encoding.UTF8.GetBytes(data);
        testData.Write(bytes, 0, bytes.Length);
        testData.Flush();
        testData.Position = pos;
#endif
    }
}


fun main() {
    val round = readLine()!!.toInt()
    var count = 0

    for (i in 1..round){
        val (m, c) = readLine()!!.split(" ").map { it.toInt() }
        if (m>c) count++ else if (m<c) count--
    }
    when{
         count > 0 -> println("Mishka")
        count < 0 -> println("Chris")
        else -> println("Friendship is magic!^^")
    }
}


import java.io.*
import java.util.*

class ProblemIO(val rd: BufferedReader, val wr: PrintWriter) {
    companion object {
        fun console() = ProblemIO(BufferedReader(InputStreamReader(System.`in`)), PrintWriter(System.out))
    }

    var tok = StringTokenizer("")

    fun close() { rd.close(); wr.close() }
    fun <T> print(v: T) = wr.print(v)
    fun <T> println(v: T) = wr.println(v)
    fun readToken(): String {
        while (!tok.hasMoreTokens()) tok = StringTokenizer(rd.readLine())
        return tok.nextToken()
    }
    fun readInt() = readToken().toInt()
    fun readLong() = readToken().toLong()
    fun readLine() : String {
        tok = StringTokenizer("")
        return rd.readLine()
    }
}

fun main(args: Array<String>) {
    Thread({ val io = ProblemIO.console(); solve(io) ; io.close() }).start()
}

fun solve(io: ProblemIO) {
    val n = io.readInt()
    var ac = 0
    var bc = 0
    for (i in 1 .. n) {
        val a = io.readInt()
        val b = io.readInt()
        if (a > b) ac += 1
        if (a < b) bc += 1
    }
    val res = when {
        ac > bc -> "Mishka"
        ac < bc -> "Chris"
        else -> "Friendship is magic!^^"
    }
    io.println(res)
}


fun main() {
    var ans1 = 0
    var ans2 = 0
    val n = readLine()!!.toInt()
    repeat(n) {
        val (a, b) = readLine()!!.split(" ").map { it.toInt() }
        if (a > b) ans1 ++
        else if (a < b) ans2 ++
    }
    if (ans1 > ans2) println("Mishka")
    else if (ans1 < ans2) println("Chris")
    else println("Friendship is magic!^^")
}


fun main()
{
    var score = 0
    val nb_round = readLine()!!.toInt()
    repeat(nb_round)
    {
        val(a, b) = readLine()!!.split(" ").map{it.toInt()}
        if (a > b) score ++
        if (a < b) score --
    }
    println(if (score == 0) "Friendship is magic!^^" else if(score > 0) "Mishka" else "Chris")

}


fun main() {
    val r = System.`in`.bufferedReader()
    val s = StringBuilder()
    val n = r.readLine()!!.toInt()
    var mw = 0
    var cw = 0
    repeat(n){
        val (m, c) = r.readLine()!!.split(" ").map { it.toInt() }
        when{
            m>c -> mw++
            m<c -> cw++
        }
    }
    when{
        mw>cw -> println("Mishka")
        mw == cw -> println("Friendship is magic!^^")
        else -> println("Chris")
    }
}


import java.util.*
import java.math.*
import kotlin.math.*

fun readLn()=readLine()!!
fun readInt()=readLn().toInt()
fun readInts()=readLn().split(" ").map{it.toInt()}
fun readLong()=readLn().toLong()
fun readLongs()=readLn().split(" ").map{it.toLong()}

val out=mutableListOf<String>()
fun printLine(s:String){out.add(s)}
fun output(){println(out.joinToString("\n"))}

fun main(){
    var n=readInt()
    var M=0;var C=0
    repeat(n){
        var (m,c)=readInts()
        if(m>c)M++
        else if(c>m)C++
    }
    if(M>C)printLine("Mishka")
    else if(C>M)printLine("Chris")
    else printLine("Friendship is magic!^^")
    output()
}


fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    var (a,b) = Pair(0,0)
    for (i in 0 until n){
        val (m,c) = readLine()!!.split(" ").map(String::toInt)
        if (m>c) a++ else if (m<c) b++
    }
    if (a>b) println("Mishka")
    else if (a<b) println("Chris")
    else println("Friendship is magic!^^")
}


fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    var M= 0 ;var C= 0
    for (i in 1..n){
        val (a,b)= readLine()!!.split(' ').map { it.toInt() }
        if(a>b)
            M++
        else if(b>a)
            C++
    }
    print(when{
        M>C -> "Mishka"
        M==C -> "Friendship is magic!^^"
        else -> "Chris"
    })
}


/* https://codeforces.com/problemset/problem/703/A */

fun main() {
    val numOfGames = readLine()!!.toInt()
    var numOfMishkaWins = 0
    var numOfChrisWins = 0
    for (i in 1..numOfGames) {
        val (mishkaResult, chrisResult) = readLine()!!.split(" ").map { it.toInt() }
        if (mishkaResult > chrisResult) {
            numOfMishkaWins++
        } else if (chrisResult > mishkaResult) {
            numOfChrisWins++
        }
    }
    if (numOfMishkaWins > numOfChrisWins) {
        println("Mishka")
    } else if (numOfChrisWins > numOfMishkaWins) {
        println("Chris")
    } else {
        println("Friendship is magic!^^")
    }
}


fun main() {
    val rounds = Integer.parseInt(readLine())
    var m = 0
    var c = 0
    for (i in 0 until rounds) {
        val inputs = readLine()!!.split(" ").map(Integer::parseInt)
        if (inputs[0] > inputs[1]) {
            m++
        } else if (inputs[0] < inputs[1]) {
            c++
        }
    }

    val output = when {
        m > c -> "Mishka"
        c > m -> "Chris"
        else -> "Friendship is magic!^^"
    }

    println(output)
}


fun main() {
    val rounds = Integer.parseInt(readLine())
    var m = 0
    var c = 0
    for (i in 0 until rounds) {
        val inputs = readLine()!!.split(" ").map(Integer::parseInt)
        if (inputs[0] < inputs[1]) {
            m++
        } else if (inputs[0] > inputs[1]) {
            c++
        }
    }

    val output = when {
        m > c -> "Mishka"
        c > m -> "Chris"
        else -> "Friendship is magic!^^"
    }

    println(output)
}


fun main() {
    var n = readLine()!!.toInt()
    var m = 0
    var c = 0
    for (i in 0 until n) {
        var num = readLine()!!.split(' ').map { it.toInt() }.toTypedArray().toIntArray()
        if      (num[0] > num[1]) m++
        else if (num[0] < num[1]) c++
    }
    if      (m > c) print("Mishka")
    else if (c > m) print("Chris")
    else            print("Friendship is magic!^^")
}


fun main() {
    var m: Int = 0
    var c: Int = 0

    val n: Int = readLine()!!.toInt()

    for (i in 0 until n) {
        var g: List<String> = readLine()!!.split(' ')
        var m1: Int = g[0].toInt()
        var c1: Int = g[1].toInt()

        if (m1 != c1) {
            if (m1 > c1) { m++ }
            else { c++ }
        }
    }

    if (m != c) {
        if (m > c) { println("Mishka") } else { println("Chris") }
    } else { println("Friendship is magic!^^") }
}


fun main() {
    val n = readLine()!!.toInt()
    var mCounter = 0
    var cCounter = 0
    for (i in 0 until n) {
        val (m, c) = readLine()!!.split(" ").map { it.toInt() }
        if (m > c) {
            mCounter++
        } else if (m < c) {
            cCounter++
        }
    }
    if (mCounter > cCounter) {
        print("Mishka")
    } else if (mCounter < cCounter) {
        print("Chris")
    } else {
        print("Friendship is magic!^^")
    }
}


private fun readLn() = readLine()!!
private fun readInt() = readLn().toInt()
private fun readStrings() = readLn().split(" ")
private fun readInts() = readStrings().map { it.toInt() }

fun main() {
    val n = readInt()
    var m = 0
    var c = 0
    repeat(n) {
        val (a, b) = readInts()
        if (a > b) m++
        if (a < b) c++
    }
    println(if (m > c) "Mishka" else if (m < c) "Chris" else "Friendship is magic!^^")
}


fun main(){
    var qty : Int = readLine()!!.toInt()
    var gamers = Array(2){0}

    for(i in 0 until qty){
        var move = readLine()!!.split(" ").map { it.toInt() }

        if(move[0] > move[1])
            gamers[0]++
        else if(move[0] < move[1])
            gamers[1]++

    }

    if(gamers[0] > gamers[1]){
        println("Mishka")
    }else if(gamers[0] < gamers[1]){
        println("Chris")
    }else{
        println("Friendship is magic!^^")
    }

}


fun main(){
    var qty : Int = readLine()!!.toInt()
    var gamers = Array(2){0}

    for(i in 0 until qty){
        var move = readLine()!!.split(" ").map { it.toInt() }

        if(move[0] > move[1])
            gamers[0]++
        else
            gamers[1]++

    }

    if(gamers[0] > gamers[1]){
        println("Mishka")
    }else if(gamers[0] < gamers[1]){
        println("Chris")
    }else{
        println("Friendship is magic!^^")
    }

}


private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints

fun main(args: Array<String>) {
    val n = readInt()
    var winA = 0
    var winB = 0
    for (i in 1..n) {
        val game = readInts()
        when {
            game[0] > game[1] -> winA ++
            game[0] < game[1] -> winB ++
        }
    }
    when {
        winA > winB -> println("Mishka")
        winA < winB -> println("Chris")
        winA == winB -> println("Friendship is magic!^^")
    }
}


fun main(){
    var m = 0
    var c = 0
    repeat(readLine()!!.toInt()) {
        var (a, b) = readLine()!!.split(" ").map { it.toInt() }
        if (a > b) m++
        if (a < b) c++
    }
    if ((m+1)*(c+1)==1 || m==c) println("Friendship is magic!^^")
    else print(if (m>c) "Mishka" else "Chris")
}


fun main() {
    val n = readLine()!!.toInt()
    var count = 0
    for (i in 1..n) {
        val (a, b) = readLine()!!.split(" ").map { it.toInt() }
        if (a > b) count++ else if (a < b) count--
    }
    when {
        count > 0 -> print("Mishka")
        count == 0 -> print("Friendship is magic!^^")
        else -> print("Chris")
    }
}


fun readInts() : List<Int> {
  val x_nullable_str = readLine()
  if (x_nullable_str == null) {
    throw Exception("Could not read ints.")
  } else {
    val x_str = x_nullable_str
    val xs = x_str.split(' ').map(String::toInt)
    return xs
  }
}

fun readInt() : Int {
  val x_nullable_str = readLine()
  if (x_nullable_str == null) {
    throw Exception("Could not read int.")
  } else {
    val x_str = x_nullable_str
    val x_str_trimmed = x_str.trim()
    val x = x_str_trimmed.toInt()
    return x
  }
}

fun main(args : Array<String>) {
  val num_rounds = readInt()
  var num_m = 0
  var num_c = 0
  for (i in 1 .. num_rounds) {
    val m_c = readInts()
    val m = m_c[0]
    val c = m_c[1]
    when (m == c) {
      true -> {}
      false -> when (m > c) {
                 true -> num_m = num_m + 1
                 else -> num_c = num_c + 1
               }
    }
  }
  when (num_m == num_c) {
    true -> println("Friendship is magic!^^")
    else -> when (num_m > num_c) {
              true -> println("Mishka")
              else -> println("Chris")
            }
  }
}


/**
 * Created by tux on 31.12.16.
 */

fun main(args: Array<String>) {
    val N = readLine()!!.split(" ").map { Integer.parseInt(it) }

    var m = 0
    var c = 0
    for (i in 0..N[0] - 1) {
        val tmp = readLine()!!.split(" ").map { Integer.parseInt(it) }
        if (tmp[0] > tmp[1]) {
            m++
        } else if (tmp[0] < tmp[1]) {
            c++
        }
    }

    println(if (m > c) "Mishka" else (if (c > m) "Chris" else "Friendship is magic!^^"))
}


fun main(args: Array<String>) {
    var n = readLine()!!.toInt()
    var A = 0
    var B = 0
    while (n > 0) {
        val (a, b) = readLine()!!.split(' ').map(String::toInt)
        if (a > b) {
            A++
        } else if (a < b) {
            B++
        }
        n--
    }
    if (A > B) {
        print("Mishka\n")
    } else if (A < B) {
        print("Chris\n")
    } else {
        print("Friendship is magic!^^\n")
    }
}


fun main(args: Array<String>) {
    val n = readLine()!!.toInt()

    val res = arrayOf(0, 0)

    (0 until n).map { readLine()!!
            .split(' ')
            .map { it.toInt() }
            .let {
                if (it[0] >= it[1]) res[0]++
                if (it[1] >= it[0]) res[1]++
            }
    }

    val d = res[0] - res[1]
    println( if (d == 0) "Friendship is magic!^^" else if (d < 0) "Chris" else "Mishka")
}


fun main(args: Array<String>) {
    val n = readLine()!!.toInt()

    (0 until n).map { readLine()!!
            .split(' ')
            .map { it.toInt() }
            .let { it[0] > it[1] }
    }.apply {
        val d = 2 * count { it } - count()
        println( if (d == 0) "Friendship is magic!^^" else if (d < 0) "Chris" else "Mishka")
    }
}


fun main(args: Array<String>) {
    val n = readLine()!!.toInt()

    val res = arrayOf(0, 0)

    (0 until n).map { readLine()!!
            .split(' ')
            .map { it.toInt() }
            .let {
                if (it[0] >= it[1]) res[0]++
                if (it[1] >= it[0]) res[0]++
            }
    }

    val d = res[0] - res[1]
    println( if (d == 0) "Friendship is magic!^^" else if (d < 0) "Chris" else "Mishka")
}


val Boolean.int get() = if (this) 1 else 0
fun main(args: Array<String>) {
  val n: Int = readLine()!!.toInt()
  var s=0
  for (i in 1..n) {
    var l=readLine()!!.split(' ')
    s=s+(l[0]>l[1]).int-(l[0]<l[1]).int
  }
  if (s>0) print("Mishka")
  else if (s==0) print("Friendship is magic!^^")
  else print("Chris")
}


#include<stdio.h>
int main()
{
    int ara[2];
    int i,j,n,a,b;
    ara[0]=0;
    ara[1]=0;
    scanf("%d",&n);
    for(i=1;i<=n;i++){
        scanf("%d%d",&a,&b);
        if(a>b)
            ara[0]++;
        if(a<b)
            ara[1]++;
    }
    if(ara[0]>ara[1])
    printf("Mishka\n");
    else if(ara[0]<ara[1])
        printf("Chris\n");
    else
        printf("Friendship is magic!^^\n");
    return 0;
}


#include<stdio.h>
int main()
{
    int ara[2];
    int i,j,n,a,b;
    ara[0]=0;
    ara[1]=0;
    scanf("%d",&n);
    for(i=1;i<=n;i++){
        scanf("%d%d",&a,&b);
        if(a>b)
            ara[0]++;
        if(a<b)
            ara[1]++;
    }
    if(ara[0]>ara[1])
    printf("Mishka\n");
    if(ara[0]<ara[1])
        printf("Chris\n");
    else
        printf("Friendship is magic!^^\n");
    return 0;
}


#include <stdio.h>
#include <math.h>

int main() {
    int rounds , msum = 0 , csum = 0;
    scanf("%d", &rounds);
    while(rounds--) {
        int mishika , chris;
        scanf("%d%d", &mishika , &chris);
        msum += mishika;
        csum += chris;
    }
    if (msum > csum) {
        printf("Mishka");
    } else if (msum < csum) {
        printf("Chris");
    } else {
        printf("Friendship is magic!^^");
    }
}


#include <stdio.h>
#include <math.h>

int main() {
    long int rounds , mcount = 0 , ccount = 0;
    scanf("%ld", &rounds);
    while(rounds--) {
        long int mishika , chris;
        scanf("%ld%ld", &mishika , &chris);
        if (mishika > chris) {
            mcount++;
        } else if (mishika < chris){
            ccount++;
        }
    }
    if (mcount > ccount) {
        printf("Mishka");
    } else if (mcount < ccount) {
        printf("Chris");
    } else {
        printf("Friendship is magic!^^");
    }
}


#include <stdio.h>
#include <math.h>

int main() {
    int rounds , mcount = 0 , ccount = 0;
    scanf("%d", &rounds);
    while(rounds--) {
        int mishika , chris;
        scanf("%d%d", &mishika , &chris);
        if (mishika > chris) {
            mcount++;
        } else {
            ccount++;
        }
    }
    if (mcount > ccount) {
        printf("Mishka");
    } else if (mcount < ccount) {
        printf("Chris");
    } else {
        printf("Friendship is magic!^^");
    }
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define ll long long
#define sf scanf
#define pf printf
#define db double
#define end return 0
int func(int,int);
int a[100005];
int main()
{
     char h[1001];
     int n,k,m=0,i,j,c=0;
     scanf("%d",&n);
     for(i=1;i<=n;i++)
     {
          scanf("%d %d",&k,&j)
          if(k>j)
          m++;
          else if(k<j)
          c++;
     }
     if(m>c)
     pf("Mishka");
     else if(c>m)
     pf("Chris");
     else
     pf("Friendship is magic!^^");
     end;
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define ll long long
#define sf scanf
#define pf printf
#define db double
#define end return 0
int func(int,int);
int a[100005];
int main()
{
     char c[1001];
     int n,k,m=0,i,j,c=0;
     scanf("%d",&n);
     for(i=1;i<=n;i++)
     {
          scanf("%d %d",&k,&j)
          if(k>j)
          m++;
          else if(k<j)
          c++;
     }
     if(m>c)
     pf("Mishka");
     else if(c>m)
     pf("Chris");
     else
     pf("Friendship is magic!^^");
     end;
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define ll long long
#define sf scanf
#define pf printf
#define db double
#define end return 0
int func(int,int);
int a[100005];
int main()
{
     char h[1001];
     int n,k,m=0,i,j,c=0;
     scanf("%d",&n);
     for(i=1;i<=n;i++)
     {
          scanf("%d %d",&k,&j);
          if(k>j)
          m++;
          else if(k<j)
          c++;
     }
     if(m>c)
     pf("Mishka");
     else if(c>m)
     pf("Chris");
     else
     pf("Friendship is magic!^^");
     end;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{ int n ,i,a,b,mish,chris;

scanf ("%d",&n);
mish=0;
chris=0;
for (i=0;i<n;i++)
{ scanf ("%d%d",&a,&b);
if (a>b)
mish++;
else
chris++;
}
if (mish>chris)
printf ("Mishka");
else if (mish<chris)
printf ("Cris");
else
printf ("Friendship is magic!^^");
    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{ int n ,i,a,b,mish,chris;

scanf ("%d",&n);
mish=0;
chris=0;
for (i=0;i<n;i++)
{ scanf ("%d%d",&a,&b);
if (a>b)
mish++;
else
chris++;
}
if (mish>chris)
printf ("Mishka");
else if (mish<chris)
printf ("chris");
else
printf ("Friendship is magic!^^");
    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{ int n ,i,a,b,mish,chris;

scanf ("%d",&n);
mish=0;
chris=0;
for (i=0;i<n;i++)
{ scanf ("%d%d",&a,&b);
if (a>b)
mish++;
else
chris++;
}
if (mish>chris)
printf ("Mishka");
else if (mish<chris)
printf ("Chris");
else
printf ("Friendship is magic!^^");
    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{ int n ,i,a,b,mish,chris;

scanf ("%d",&n);
mish=0;
chris=0;
for (i=0;i<n;i++)
{ scanf ("%d%d",&a,&b);
if (a>b)
mish++;
else if (a<b)
chris++;
}
if (mish>chris)
printf ("Mishka");
else if (mish<chris)
printf ("Chris");
else
printf ("Friendship is magic!^^");
    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
FILE *fp;
    fp=fopen("abc.txt","r");
int i,a,b,mish,chris;
long long n ;

fscanf (fp,"%lld",&n);
mish=0;
chris=0;
for (i=0;i<n;i++)
{ fscanf (fp,"%d%d",&a,&b);
if (a>b)
mish++;
else if (a<b)
chris++;
}
printf ("%d \n",mish);
printf ("%d \n",chris);
if (mish>chris)
printf ("Mishka");
else if (mish<chris)
printf ("cris");
else
printf ("Friendship is magic!^^");
    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{ int n ,i,a,b,mish,chris;

scanf ("%d",&n);
mish=0;
chris=0;
for (i=0;i<n;i++)
{ scanf ("%d%d",&a,&b);
if (a>b)
mish++;
else
chris++;
}
if (mish>chris)
printf ("Mishka");
else if (mish<chris)
printf ("cris");
else
printf ("Friendship is magic!^^");
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
int main()
{
     int n,mi,ci,w=0,s1=0,s2=0,c;
     long l='Friendship is magic!^^';
     scanf("%d",&n);
     if(n>=1 && n<=100)
{
     for(c=1;c<=n;c++)
{
     scanf("%d %d",&mi,&ci);
     if(mi>ci)
     s1++;
     else if (mi<ci)
     s2++;
     else w=l;
}
     if(s1>s2)
     printf("Mishka\n");
     else if(s1<s2)
     printf("Chris\n");
     else printf("Friendship is magic!^^\n");
}
     else printf("wronge valid\n");

return 0;
}


#include <stdio.h>
#include <stdlib.h>
int main()
{int n,mi,ci,s1=0,s2=0,c;
scanf("%d",&n);
if(n>=1 && n<=100)
{for(c=1;c<=n;c++){
scanf("%d %d",&mi,&ci);
s1=s1+mi;
s2=s2+ci;}
if(s1>s2)
printf("Mishka\n");
else if(s1<s2)
printf("Chris\n");
else printf("Friendship is magic!^^\n");
}else printf("wronge valid\n");
return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
   int n,mi,ci,s1=0,s2=0,c;
   scanf("%d",&n);
   if(n>=1 && n<=100)
   {
       for(c=1;c<=n;c++)
       {
           scanf("%d %d",&mi,&ci);
           s1=s1+mi;
           s2=s2+ci;
       }
       if(s1>s2)
       printf("Mishka");
       else if(s1<s2)
       printf("Chris");
       else printf("Friendship is magic!^^");
   }
    else printf("wronge valid");

    return 0;
}


#include <stdio.h>
#include <stdlib.h>
int main()
{int n,mi,ci,s1=0,s2=0,c;
scanf("%d",&n);
if(n>=1 && n<=100)
{for(c=1;c<=n;c++){
scanf("%d %d",&mi,&ci);
s1=s1+mi;
s2=s2+ci;}
if(s1>s2)
printf("Mishka");
else if(s1<s2)
printf("Chris");
else printf("Friendship is magic!^^");
}else printf("wronge valid");
return 0;
}


#include<stdio.h>
int main()
{
    int n,i,a,b,m[100],c[100],x=0,y=0,z=0;
    scanf("%d", &n);
    for(i=0; i<n; i++){
        scanf("%d %d", &m[i],&c[i]);
    }
    for(i=0; i<n; i++){
        if(m[i]>c[i]){
            x++;
        }
        if(m[i]<c[i]){
            y++;
        }
        if(m[i]==c[i]){
           z++;
        }
    }
    if(x>y){
        printf("Mishka");
    }
    else if(y>x){
        printf("Chris");
    }
    else if(x=y){
        printf("Friendship is magic!^^");
    }
    else if(z>x && z>y){
        printf("Friendship is magic!^^");
    }
    return 0;
}


#include<stdio.h>
int main()
{
    int n,i,a,b,m[100],c[100],x=0,y=0;
    scanf("%d", &n);
    for(i=0; i<n; i++){
        scanf("%d %d", &m[i],&c[i]);
    }
    for(i=0; i<n; i++){
        if(m[i]>c[i]){
            x++;
        }
        if(m[i]<c[i]){
            y++;
        }
    }
    if(x>y){
        printf("Mishka");
    }
    else if(y>x){
        printf("Chris");
    }
    else if(x=y){
        printf("Friendship is magic!^^");
    }
    return 0;
}


#include<stdio.h>
int main()
{
    int round_number,row,column,array[round_number+1][2],mishka=0,chris=0;
    scanf("%d",&round_number);
    for(row=0; row<round_number; row++)
    {
        for(column=0; column<2; column++)
        {
            scanf("%d",&array[row][column]);
        }
    }
    for(row=0;row<round_number;row++)
    {
        if(array[row][0]>array[row][1])
        {
            mishka++;

        }
        else if(array[row][0]<array[row][1])
        {
            chris++;
        }
        else if(array[row][0]==array[row][1])
        {
            chris++;
            mishka++;
        }

    }
    if(mishka>chris)
    {
        printf("Mishka");
    }
    else if (mishka<chris)
    {
        printf("Chris");
    }
    else if(mishka==chris)
    {
        printf("Friendship is magic!^^");
    }

}


#include<stdio.h>
int main()
{
    int round_number,row,column,array[round_number+1][3],mishka=0,chris=0;
    scanf("%d",&round_number);
    for(row=0; row<round_number; row++)
    {
        for(column=0; column<2; column++)
        {
            scanf("%d",&array[row][column]);
        }
    }
    for(row=0;row<round_number;row++)
    {
        if(array[row][0]>array[row][1])
        {
            mishka++;

        }
        else if(array[row][0]<array[row][1])
        {
            chris++;
        }
        else if(array[row][0]==array[row][1])
        {
            chris++;
            mishka++;
        }

    }
    if(mishka>chris)
    {
        printf("Mishka");
    }
    else if (mishka<chris)
    {
        printf("Chris");
    }
    else if(mishka==chris)
    {
        printf("Friendship is magic!^^");
    }

}


#include<stdio.h>
int main()
{
    int round_number,row,column,array[round_number+1][2],mishka=0,chris=0;
    scanf("%d",&round_number);
    for(row=0; row<round_number; row++)
    {
        for(column=0; column<2; column++)
        {
            scanf("%d",&array[row][column]);
        }
    }
    for(row=0;row<round_number;row++)
    {
        if(array[row][0]>array[row][1])
        {
            mishka++;

        }
        else if(array[row][0]<array[row][1])
        {
            chirs++;
        }
        else if(array[row][0]==array[row][1])
        {
            chris++;
            mishka++;
        }

    }
    if(mishka>chris)
    {
        printf("Mishka");
    }
    else if (mishka<chris)
    {
        printf("Chris");
    }
    else if(mishka==chris)
    {
        printf("Friendship is magic!^^");
    }

}


#include<stdio.h>
int main()
{
    int round_number,row,column,array[round_number+1][3],mishka=0,chris=0;
    scanf("%d",&round_number);
    for(row=0; row<round_number; row++)
    {
        for(column=0; column<2; column++)
        {
            scanf("%d",&array[row][column]);
        }
         if(array[row][0]>array[row][1])
        {
            mishka++;

        }
        else if(array[row][0]<array[row][1])
        {
            chris++;
        }
        else if(array[row][0]==array[row][1])
        {
            chris++;
            mishka++;
        }

    }

    if(mishka>chris)
    {
        printf("Mishka");
    }
    else if (mishka<chris)
    {
        printf("Chris");
    }
    else if(mishka==chris)
    {
        printf("Friendship is magic!^^");
    }

return 0;

}


#include<stdio.h>
int main()
{
    int round_number,row,column,array[100][3],mishka=0,chris=0;
    scanf("%d",&round_number);
    for(row=0; row<round_number; row++)
    {
        for(column=0; column<2; column++)
        {
            scanf("%d",&array[row][column]);
        }
         if(array[row][0]>array[row][1])
        {
            mishka++;

        }
        else if(array[row][0]<array[row][1])
        {
            chris++;
        }
        else if(array[row][0]==array[row][1])
        {
            chris++;
            mishka++;
        }

    }

    if(mishka>chris)
    {
        printf("Mishka");
    }
    else if (mishka<chris)
    {
        printf("Chris");
    }
    else if(mishka==chris)
    {
        printf("Friendship is magic!^^");
    }

return 0;

}


#include<stdio.h>
int main()
{
    int n,a,b,i,c=0,q,p,r=0;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d %d",&a,&b);
        if(a>b) c++;
        if(a==b) r++;

    }
    printf("%d\n",r);
    printf("%d\n",c);
    p=c;
    q=(n-c)-r;

    if(p>q) printf("Mishka\n");
    else if(q>p) printf("Chris\n");
    else printf("Friendship is magic!^^\n");
    return 0;

}


#include<stdio.h>
int main()
{
    int n,a,b,i,c=0,q,p,r=0;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d %d",&a,&b);
        if(a>b) c++;
        if(a==b) r++;

    }
    p=c;
    q=(n-c)-r;

    if(p>q) printf("Mishka\n");
    else if(q>p) printf("Chris\n");
    else printf("Friendship is magic!^^\n");
    return 0;

}


#include<stdio.h>
int main()
{
    int n,a,b,i,c=0,q,p;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d %d",&a,&b);
        if(a>b) c++;

    }
    p=c;
    q=(n-c);

    if(p>q) printf("Mishka\n");
    else if(q>p) printf("Chris\n");
    else printf("Friendship is magic!^^\n");
    return 0;

}


#include<stdio.h>
int main()
{
    int n,a,b,i,p=0,q=0;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d %d",&a,&b);
        p=p+a;
        q=q+b;

    }
    if(p>q) printf("Mishka\n");
    else if(q>p) printf("Chris\n");
    else printf("Friendship is magic!^^\n");
    return 0;

}


#include <stdio.h>

int main(void) {
	int n,i,m,c,mcnt=0,ccnt=0;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		scanf("%d%d",&m,&c);
		if(m>c)mcnt++;
		else if(c>m)ccnt++;
	}
	if(mcnt>ccnt)printf("Mishka\n");
	else if(ccnt>mcnt)printf("Chris\n");
	else printf("Friendship is magic!^^\n");
	return 0;
}


#include <stdio.h>

int main(void) {
	int n,i,m,c,mcnt=0,ccnt=0;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		scanf("%d%d",&m,&c);
		if(m>c)mcnt++;
		else if(c<m)ccnt++;
	}
	if(mcnt>ccnt)printf("Mishka\n");
	else if(ccnt>mcnt)printf("Chris\n");
	else printf("Friendship is magic!^^\n");
	return 0;
}


#include <stdio.h>

int main(void) {
	int n,i,m,c,mcnt=0,ccnt=0;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		scanf("%d%d",&m,&c);
		if(m>c)mcnt++;
		else ccnt++;
	}
	if(mcnt>ccnt)printf("Mishka\n");
	else if(ccnt>mcnt)printf("Chris\n");
	else printf("Friendship is magic!\n");
	return 0;
}


#include <stdio.h>

int main(void) {
	int n,i,m,c,mcnt=0,ccnt=0;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		scanf("%d%d",&m,&c);
		if(m>c)mcnt++;
		else ccnt++;
	}
	if(mcnt>ccnt)printf("Mishka\n");
	else if(ccnt>mcnt)printf("Chris\n");
	else printf("Friendship is magic!^^\n");
	return 0;
}


#include<stdio.h>
int main()
{
	int n,x,y;
	int m=0,c=0;
	scanf("%d",&n);
	while(n>0)
	{
		scanf("%d",&x);
		scanf("%d",&y);
		if(x>y)
		m=m+1;
		else if (x<y)
		c=c+1;
		n--;
	}
	if(m>c)
	printf("Mishka");
	else if (m<c)
	printf("Chris");
    else
	printf("Friendship is magic!^^");

}


#include<stdio.h>
int main()
{
	int n,x,y;
	int m=0,c=0;
	scanf("%d",&n);
	while(n>0)
	{
		scanf("%d",&x);
		scanf("%d",&y);
		if(x>y)
		m=m+1;
		else
		c=c+1;
		n--;
	}
	if(m>c)
	printf("Mishka");
	else if (m<c)
	printf("Chris");
    else
	printf("Friendship is magic!^^");

}


n=int(input())
m=0,c=0
while(n>0):
    x,y=int(input()),int(input())
    if(x>y):
        m=m+1
    else :
        c=c+1
    n=n-1
if(m>c):
    print("Mishka")
elif(m<c):
    print("Chris")
else :
    print("Friendship is magic!^^")


n= int(input())
m=0,c=0
while(n>0):
    x,y=raw_input().split()
    if(x>y):
        m=m+1
    else :
        c=c+1
    n=n-1
if(m>c):
    print("Mishka")
elif(m<c):
    print("Chris")
else :
    print("Friendship is magic!^^")


#include<stdio.h>
int main()
{
int n,m,c,M=0,C=0;
scanf("%d",&n);
while(n--)
	{
	scanf("%d%d",&m,&c);
	if(m>c) ++M;
	else if (c>m) ++C;
	else ;
	}
if(M>c) printf("Mishka\n");
else if(C>M) printf("Chris\n");
else printf("Friendship is magic!^^\n");
return 0;
}


#include<stdio.h>
int main()
{
int n,m,c,M=0,C=0;
scanf("%d",&n);
while(n--)
	{
	scanf("%d%d",&m,&c);
	if(m>c) ++M;
	else if (c>m) ++C;
	else ;
	}
if(M>C) printf("Mishka\n");
else if(C>M) printf("Chris\n");
else printf("Friendship is magic!^^\n");
return 0;
}


#include<stdio.h>
int main()
{
int n,x,y,m=0,c=0;
scanf("%d",&n);
while(n--)
{scanf("%d%d",&x,&y);if(x>y)++m;if(y>x)++c;}
if (m>c)printf("Mishka\n");
else if (m<c)printf("Chris\n");
else printf("Friendship is magic!^^\n");
return 0;
}


#include<stdio.h>
int main()
{
    int a,b,i,n,m=0,c=0;

    scanf("%d",&n);

    for(i=0;i<n;i++)
        {
            scanf("%d %d",&a, &b);

              if(a>b)
              {
                  m++;
              }
              else
              {
                c++;
              }

        }

        if(m>c)

            printf("Mishka\n");

        else if(m<c)

            printf("Chris\n");

        else

            printf("Friendship is magic!^^\n");

            return 0;
}


#include<stdio.h>
int main()
{
    int a,b,i,n,m=0,c=0;

    scanf("%d",&n);

    for(i=0;i<n;i++)
        {
            scanf("%d %d",&a, &b);

              if(a>b)
              {
                  ++m;
              }
              else
              {
                ++c;
              }

        }

        if(m>c)

            printf("Mishka\n");

        else if(m<c)

            printf("Chris\n");

        else

            printf("Friendship is magic!^^\n");

            return 0;
}


#include<stdio.h>
int main()
{
    int a[100],b[100],i,n,m=0,c=0;

    scanf("%d",&n);

    for(i=0;i<n;i++)
        {
            scanf("%d %d",&a[i], &b[i]);

              if(a[i]>b[i])
              {
                  m++;
              }
              else
              {
                c++;
              }

        }

        if(m>c)

            printf("Mishka");

        else if(m<c)

            printf("Chris");

        else

            printf("Friendship is magic!^^");

            return 0;
}


#include<stdio.h>
int main()
{
    int a,b,i,n,m=0,c=0;

    scanf("%d",&n);

    for(i=0;i<n;i++)
        {
            scanf("%d %d",&a, &b);

              if(a>b)
              {
                  ++m;
              }
              if(a<b)
              {
                ++c;
              }

        }

        if(m>c)

            printf("Mishka\n");

        else if(m<c)

            printf("Chris\n");

        else

            printf("Friendship is magic!^^\n");

            return 0;
}


#include<stdio.h>
int main()
{
    int a[200],i,n,m=0,c=0;
    scanf("%d",&n);
    for(i=2;i<((n*2)+2);i++)
    {
        scanf("%d",&a[i]);
        if(i%2==0)
        {
            m=m+a[i];

        }
        else
        {
            c=c+a[i];
        }
    }
    if(m>c)
        printf("Mishka");
    else if(m==c)
        printf("Friendship is magic!^^");
    else
        printf("Chris");
}


/*������� � ����� ������: ������� ������������ �������� n � ����������
 ������� ����. � ��������� ������ ������ �� ������� ���� ��� �������
  ����������� ��������� �����, �� ����� �������� �������� ��������� �����
  �� 1 �� 6. �����, ����������� ������� ��������, ���������� �����������
   � ������. � ������, ���� �������� �������� �����,
   ������ �� ������������� ������.*/

        /*����������� �� ������� �� ����: 1 �������
          ����������� �� ������ �� ����: 256 ��������
          ����: ����������� ����
          �����: ����������� �����*/

#include <stdio.h>
#include <time.h>
int main()
{
    int n, i, counterM, counterC;
    scanf("%d", &n);
    int m[n], c[n];
    counterM = 0;
    counterC = 0;
    //srand(time(NULL));
    for (i = 0; i < n; i++)
    {
        //m[i] = 1 + rand()%6;
        scanf("%d", &m[i]);
        //printf("%d\t", m[i]);
        //c[i] = 1 + rand()%6;
        scanf("%d", &c[i]);
        //printf("%d\n", c[i]);
        if (m[i] > c[i])
            ++counterM;
        if (c[i] > m[i])
            ++counterC;
    }
    if (counterM == counterC)
        printf("Friendship is magic!^^");
    if (counterM > counterC)
        printf("Mishka");
    else if (counterC > counterM)
        printf("Chris");
    return 0;
}


/*������� � ����� ������: ������� ������������ �������� n � ����������
 ������� ����. � ��������� ������ ������ �� ������� ���� ��� �������
  ����������� ��������� �����, �� ����� �������� �������� ��������� �����
  �� 1 �� 6. �����, ����������� ������� ��������, ���������� �����������
   � ������. � ������, ���� �������� �������� �����,
   ������ �� ������������� ������.*/

        /*����������� �� ������� �� ����: 1 �������
          ����������� �� ������ �� ����: 256 ��������
          ����: ����������� ����
          �����: ����������� �����*/

#include <stdio.h>
#include <time.h>
int main()
{
    int n, i, counterM, counterC;
    scanf("%d", &n);
    int m[n], c[n];
    counterM = 0;
    counterC = 0;
    srand(time(NULL));
    for (i = 0; i < n; i++)
    {
        m[i] = 1 + rand()%6;
        printf("%d\t", m[i]);
        c[i] = 1 + rand()%6;
        printf("%d\n", c[i]);
        if (m[i] > c[i])
            ++counterM;
        if (c[i] > m[i])
            ++counterC;
    }
    printf("Wins Mishka: %d\n", counterM);
    printf("Wins Chris: %d\n", counterC);
    if (counterM == counterC)
        printf("Friendship is magic!^^");
    if (counterM > counterC)
        printf("Mishka Wins!\n");
    else if (counterC > counterM)
        printf("Chris Wins!\n");
    return 0;
}


/*������� � ����� ������: ������� ������������ �������� n � ����������
 ������� ����. � ��������� ������ ������ �� ������� ���� ��� �������
  ����������� ��������� �����, �� ����� �������� �������� ��������� �����
  �� 1 �� 6. �����, ����������� ������� ��������, ���������� �����������
   � ������. � ������, ���� �������� �������� �����,
   ������ �� ������������� ������.*/

        /*����������� �� ������� �� ����: 1 �������
          ����������� �� ������ �� ����: 256 ��������
          ����: ����������� ����
          �����: ����������� �����*/

#include <stdio.h>
#include <time.h>
int main()
{
    int n, i, counterM, counterC;
    scanf("%d", &n);
    int m[n], c[n];
    counterM = 0;
    counterC = 0;
    srand(time(NULL));
    for (i = 0; i < n; i++)
    {
        m[i] = 1 + rand()%6;
        printf("%d\t", m[i]);
        c[i] = 1 + rand()%6;
        printf("%d\n", c[i]);
        if (m[i] > c[i])
            ++counterM;
        if (c[i] > m[i])
            ++counterC;
    }
    if (counterM == counterC)
        printf("Friendship is magic!^^");
    if (counterM > counterC)
        printf("Mishka");
    else if (counterC > counterM)
        printf("Chris");
    return 0;
}


/*������� � ����� ������: ������� ������������ �������� n � ����������
 ������� ����. � ��������� ������ ������ �� ������� ���� ��� �������
  ����������� ��������� �����, �� ����� �������� �������� ��������� �����
  �� 1 �� 6. �����, ����������� ������� ��������, ���������� �����������
   � ������. � ������, ���� �������� �������� �����,
   ������ �� ������������� ������.*/

        /*����������� �� ������� �� ����: 1 �������
          ����������� �� ������ �� ����: 256 ��������
          ����: ����������� ����
          �����: ����������� �����*/

#include <stdio.h>
#include <time.h>
int main()
{
    int n, i, counterM, counterC;
    printf("Enter the number of rounds: ");
    scanf("%d", &n);
    int m[n], c[n];
    counterM = 0;
    counterC = 0;
    srand(time(NULL));
    for (i = 0; i < n; i++)
    {
        m[i] = 1 + rand()%6;
        printf("%d\t", m[i]);
        c[i] = 1 + rand()%6;
        printf("%d\n", c[i]);
        if (m[i] > c[i])
            ++counterM;
        if (c[i] > m[i])
            ++counterC;
    }
    //printf("Wins Mishka: %d\n", counterM);
    //printf("Wins Chris: %d\n", counterC);
    if (counterM == counterC)
        printf("Friendship is magic!^^");
    if (counterM > counterC)
        printf("Mishka\n");
    else if (counterC > counterM)
        printf("Chris\n");
    return 0;
}


#include <stdio.h>

int main()
{
  int n,mishka,chris,m,c,i;
  mishka=0;
  chris=0;
  scanf("%d",&n);
  for (i=0;i<n;i++){
    scanf("%d %d",&m,&c);
    if (m>c)
      mishka++;
    if (c>m)
    chris++;
  }
  if (mishka>chris)
    printf("Mishka\n");
  else if (chris>mishka)
    printf("Chris\n");
  else
    printf("Frienship is magic!^^\n");
  return 0;
}


#include <stdio.h>

int main()
{
  int n,mishka=0,chris=0,m,c,i;
  scanf("%d",&n);
  for (i=0;i<n;i++){
    scanf("%d %d",&m,&c);
    if (m>c)
      mishka++;
    if (c>m);
    chris++;
  }
  if (mishka>chris)
    printf("Mishka\n");
  if (chris>mishka)
    printf("Chris\n");
  else
    printf("Frienship is magic!^^\n");
  return 0;
}


#include <stdio.h>

int main()
{
  int n,mishka,chris,m,c,i;
  mishka=0;
  chris=0;
  scanf("%d",&n);
  for (i=0;i<n;i++){
    scanf("%d %d",&m,&c);
    if (m>c)
      mishka++;
    if (c>m)
    chris++;
  }
  if (mishka>chris)
    printf("Mishka\n");
  else if (chris>mishka)
    printf("Chris\n");
  else
    printf("Friendship is magic!^^\n");
  return 0;
}


#include<stdio.h>

int main(){
   int n,i,a,b,s1=0,s2=0;
   scanf("%d",&n);
   for(i=0;i<n;i++){
    scanf("%d %d",&a,&b);
    if(a>b) s1++;
    else if(a<b) s2++;
   }
   if(s1>s2) printf("Mishka");
   else if(s1<s2) printf("Chris");
   else printf("Friendship is magic!^^");
    return 0;
}


#include<stdio.h>

int main(){
   int n,i,a,b,s1=0,s2=0;
   scanf("%d",&n);
   for(i=0;i<n;i++){
    scanf("%d %d",&a,&b);
    if(a>b) s1++;
    else s2++;
   }
   if(s1>s2) printf("Mishka");
   else if(s1<s2) printf("Chris");
   else printf("Friendship is magic!^^");
    return 0;
}


#include<stdio.h>

int main()
{
    int i, n, m,c;
    int miwin=0, chwin=0;
    scanf("%d", &n);
    for(i=0; i<n; i++)
    {
        scanf("%d %d", &m, &c);
        if(m>c)
            miwin++;
        else if(c>m)
            chwin++;
        else
            continue;
    }
    if(miwin==chwin)
        printf("Friendship is magic!^^");
    else if(miwin>chwin)
        printf("Mishka");
    else
        printf("Chris");

    return 0;
}


#include<stdio.h>

int main()
{
    int i, n, m,c;
    int miwin=0, chwin=0;
    scanf("%d", &n);
    for(i=0; i<n; i++)
    {
        scanf("%d %d", &m, &c);
        miwin=miwin+m;
        chwin=chwin+c;
    }
    if(miwin==chwin)
        printf("Friendship is magic!^^");
    else if(miwin>chwin)
        printf("Mishka");
    else
        printf("Chris");

    return 0;
}


#include <stdio.h>
int main()
{
    int n, m[101], c[101], i, sum1 = 0, sum2 = 0;

    scanf("%d", &n);
    for(i = 0; i < n; i++){
        scanf("%d %d", &m[i], &c[i]);
        sum1 = sum1 + m[i];
        sum2 = sum2 + c[i];
    }
    if(sum1 > sum2){
        printf("Mishka\n");
    }
    else if(sum2 > sum1){
        printf("Chris\n");
    }
    else{
        printf("Friendship is magic!^^\n");
    }

    return 0;
}


#include <stdio.h>
int main()
{
    int n, m, c, i, M = 0, C = 0;

    scanf("%d", &n);
    for(i = 0; i < n; i++){
        scanf("%d %d", &m, &c);
        if(m > c){
            M++;
        }
        else if(c > m){
            C++;
        }
    }
    if(M > C){
        printf("Mishka\n");
    }
    else if(C > M){
        printf("Chris\n");
    }
    else{
        printf("Friendship is magic!^^\n");
    }
    return 0;
}


#include <stdio.h>
int main()
{
    int n, m, c, i, M = 0, C = 0;

    scanf("%d", &n);
    for(i = 0; i < n; i++){
        scanf("%d %d", &m, &c);
        if(m > c){
            M++;
        }
        else{
            C++;
        }
    }
    if(M > C){
        printf("Mishka\n");
    }
    else if(C > M){
        printf("Chris\n");
    }
    else{
        printf("Friendship is magic!^^\n");
    }
    return 0;
}


#include "stdio.h"

int main()
{
	int i, n, m[100], c[100],sm=0,sc=0;
	scanf("%d", &n);
	for (i = 1;i <= n;i++) {
		scanf("%d %d", &m[i], &c[i]);
	}
	for (i = 1;i <= n;i++) {
		if (m[i] > c[i])
			sm++;
		else
			sc++;
	}

	if (sm > sc) {
		printf("Mishka");
	}
	if(sc>sm)
		printf("Chris");
	if (sc == sm)
		printf("Friendship is magic!^^");

	return 0;
}


#include "stdio.h"

int main()
{
	int i, n, m[100], c[100],sm=0,sc=0;
	scanf("%d", &n);
	for (i = 1;i <= n;i++) {
		scanf("%d %d", &m[i], &c[i]);
	}
	for (i = 1;i <= n;i++) {
		 sm += m[i];
	}
	for (i = 1;i <= n;i++) {
		sc += c[i];
	}
	if (sm > sc) {
		printf("Mishka");
	}
	if(sc>sm)
		printf("Chris");
	if (sc == sm)
		printf("Friendship is magic!^^");

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MOD = 1e9 + 7, N = 2011;

int m, d;
int dp[N][N][2], power[N];

void make_powers() {
	power[0] = 1;
	for (int i = 1; i < 2001; i++)
		power[i] = (power[i - 1] * 10) % m;
}

long cal(string s) {
	int n = s.size();
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			for (int k = 0; k < 10; k++)
					dp[i][j][k] = 0;
	for (int i = 1; i <= s[0] - '0'; i++) {
		if (i == d)
			continue;
		long rem = i * power[n - 1] % m;
		if (i != s[0] - '0')
			dp[0][rem][0]++;
		else
			dp[0][rem][1]++;
	}

	for (int i = 1; i < n; i++)
		for (int j = 0; j < m; j++) {

			if (i % 2 == 0) {
				for (int k = 0; k < 10; k++) {
					if (k == d)
					continue;
					int rem = ((j + m) - (k * power[n - i - 1]) % m) % m;
					if (i % 2 == 0) {
						if (k <= s[i] - '0') {
							if (k == s[i] - '0')
								dp[i][j][1] += dp[i - 1][rem][1];
							else dp[i][j][0] = (dp[i][j][0] + dp[i - 1][rem][1]) % MOD;
						}
						dp[i][j][0] = (dp[i][j][0] + dp[i - 1][rem][0]) % MOD;
					}
				}
			}
			else {
				int rem = ((j + m) - (d * power[n - i - 1]) % m) % m;
				if (d > s[i] - '0')
					dp[i][j][0] = dp[i - 1][rem][0] ;
				else if (d == s[i] - '0')
					dp[i][j][1] = dp[i - 1][rem][1] + dp[i - 1][rem][0];
				else dp[i][j][0] = dp[i - 1][rem][1] + dp[i - 1][rem][0];
			}
		}

	long ans = dp[n - 1][0][0] + dp[n - 1][0][1];
	ans %= MOD;
	return ans;
}

main() {
	string s, t;
	cin >> m >> d >> s >> t;
	make_powers();

	long long ans = (cal(t) + MOD - cal(s)) % MOD;
	int rem = 0;
	bool d_magic = true;
	for (int i = 0; i < s.size(); i++) {
		if (i % 2 && s[i] - '0' != d)
			d_magic = false;
		rem = (rem * 10 + (s[i] - '0')) % m;
	}
	if (rem)
		d_magic = false;
	ans = (ans + d_magic) % MOD;
	cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define N 2009
#define ll long long
#define MOD 1000000007
int m,d,n;
char l[N],r[N];
ll dp[2][N][N];
ll pre[N][N];
ll f[N];
inline void init()
{
	f[0]=1%m;
	for(int i=1;i<N-2;i++)f[i]=(f[i-1]*10)%m;
	memset(dp,-1,sizeof(dp));
	//memset(pre,-1,sizeof(pre));
	//precompute();
}
ll precompute()//int k,int mod,int i)//another dp
{
	pre[0][0]=1;
	for(int k=0;k<=9;k++)
	{
		if(k==d)continue;
		pre[1][k%m]++;
		pre[2][(k*10+d)%m]++;
	}
	for(int i=3;i<=n;i+=2)
	{
		for(int j=0;j<m;j++)//mod
		{
			if(pre[i-1][j])
			for(int k=0;k<=9;k++)//dig
			{
				if(k==d)continue;
				pre[i][(j*10+k)%m]+=pre[i-1][j];
			}
		}
		for(int j=0;j<m;j++)//mod
		{
			if(pre[i][j])
			//for(int k=0;k<=9;k++)//dig
			{
				pre[i+1][(j*10+d)%m]+=pre[i][j];
			}
		}
		for(int j=0;j<m;j++)
		{
			pre[i][j]%=MOD;
			pre[i+1][j]%=MOD;
		}
	}
}
ll calc(char r[],int mod,int i,int ch)
{
	if(i==n)return 1;
	if(i>=n)return 0;
	if(dp[ch][mod][i]!=-1)return dp[ch][mod][i];
	dp[ch][mod][i]=0;
	if(i+2>n)
	{
		for(int j=(i==0?1:0);j<=9;j++)
		{
			if(j==d)continue;
			if(r[i+1]<j+'0')break;
			//cout<<"i="<<i<<" mod="<<mod<<" j="<<j<<endl;
			if((mod-(j*f[n-i-1])%m+m)%m==0)dp[ch][mod][i]++;
		}
		return (dp[ch][mod][i]%=MOD);
	}
	for(int j=(i==0?1:0);j<=9;j++)
	{
		if(j==d)continue;
		ll t=(mod-(j*f[n-i-1]+d*f[n-i-2])%m+m)%m;
		//cout<<"i="<<i<<" mod="<<mod<<" j="<<j<<" aux="<<(j*f[n-i-1]+d*f[n-i-2])<<" t="<<t;
		if(r[i+2]==d+'0' && r[i+1]==j+'0'){//cout<<endl<<"new calc"<<endl;
		dp[ch][mod][i]+=calc(r,t,i+2,ch);}
		else if(r[i+2]<d+'0' && r[i+1]<=j+'0')break;
		else if(r[i+1]>=j+'0'){dp[ch][mod][i]+=pre[n-i-2][t];
		//cout<<" pre[n-i-2][t]="<<pre[n-i-2][t]<<endl;
		}
		else break;
	}
	//cout<<"dp[ch][mod][i]="<<(dp[ch][mod][i]%=MOD)<<endl;
	return (dp[ch][mod][i]%=MOD);
}
int main()
{
	cin>>m>>d;
	cin>>l+1>>r+1;
	//cout<<"l="<<l+1<<endl<<"r="<<r+1<<endl;
	n=strlen(l+1);
	init();
	//cout<<"ll"<<endl;
	precompute();
	//cout<<"n="<<n<<endl;
	//for(int i=1;i<=n;i++){for(int j=0;j<=m;j++)cout<<pre[i][j]<<" ";cout<<endl;}
	ll p=calc(r,0,0,1);
	//decrement(l);
	ll q=calc(l,0,0,0);
	ll t=-1;
	for(int i=1;i<=n;i+=2)if(l[i]==d+'0' || (i+1<=n && l[i+1]!=d+'0')){t=0;break;}
	if(t!=0)
	{
		t=0;
		for(int i=1;i<=n;i++)t=(t*10+l[i]-'0')%m;
		if(t!=0)t=0;
		else t=1;
	}
	//cout<<"p="<<p<<" q="<<q<<" t="<<t<<endl;
	cout<<(p-q+t+MOD)%MOD<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define N 2009
#define ll long long
#define MOD 1000000007
int m,d,n;
char l[N],r[N];
ll dp[2][N][N];
ll pre[N][N];
ll f[N];
inline void init()
{
	f[0]=1%m;
	for(int i=1;i<N-2;i++)f[i]=(f[i-1]*10)%m;
	memset(dp,-1,sizeof(dp));
	//memset(pre,-1,sizeof(pre));
	//precompute();
}
ll precompute()//int k,int mod,int i)//another dp
{
	pre[0][0]=1;
	for(int k=0;k<=9;k++)
	{
		if(k==d)continue;
		pre[1][k%m]++;
		pre[2][(k*10+d)%m]++;
	}
	for(int i=3;i<=n;i+=2)
	{
		for(int j=0;j<m;j++)//mod
		{
			if(pre[i-1][j])
			for(int k=0;k<=9;k++)//dig
			{
				if(k==d)continue;
				pre[i][(j*10+k)%m]+=pre[i-1][j];
			}
		}
		for(int j=0;j<m;j++)//mod
		{
			if(pre[i][j])
			//for(int k=0;k<=9;k++)//dig
			{
				pre[i+1][(j*10+d)%m]+=pre[i][j];
			}
		}
		for(int j=0;j<m;j++)
		{
			pre[i][j]%=MOD;
			pre[i+1][j]%=MOD;
		}
	}
}
ll calc(char r[],int mod,int i,int ch)
{
	if(i>=n)return 0;
	if(dp[ch][mod][i]!=-1)return dp[ch][mod][i];
	dp[ch][mod][i]=0;
	if(i+2>n)
	{
		for(int j=(i==0?1:0);j<=9;j++)
		{
			if(j==d)continue;
			if(r[i+1]<j+'0')break;
			//cout<<"i="<<i<<" mod="<<mod<<" j="<<j<<endl;
			if((mod-(j*f[n-i-1])%m+m)%m==0)dp[ch][mod][i]++;
		}
		return (dp[ch][mod][i]%=MOD);
	}
	for(int j=(i==0?1:0);j<=9;j++)
	{
		if(j==d)continue;
		ll t=(mod-(j*f[n-i-1]+d*f[n-i-2])%m+m)%m;
		//cout<<"i="<<i<<" mod="<<mod<<" j="<<j<<" aux="<<(j*f[n-i-1]+d*f[n-i-2])<<" t="<<t;
		if(r[i+2]==d+'0' && r[i+1]==j+'0'){//cout<<endl<<"new calc"<<endl;
		dp[ch][mod][i]+=calc(r,t,i+2,ch);}
		else if(r[i+2]<d+'0' && r[i+1]<=j+'0')break;
		else if(r[i+1]>=j+'0'){dp[ch][mod][i]+=pre[n-i-2][t];
		//cout<<" pre[n-i-2][t]="<<pre[n-i-2][t]<<endl;
		}
		else break;
	}
	//cout<<"dp[ch][mod][i]="<<(dp[ch][mod][i]%=MOD)<<endl;
	return (dp[ch][mod][i]%=MOD);
}
int main()
{
	cin>>m>>d;
	cin>>l+1>>r+1;
	//cout<<"l="<<l+1<<endl<<"r="<<r+1<<endl;
	n=strlen(l+1);
	init();
	//cout<<"ll"<<endl;
	precompute();
	//cout<<"n="<<n<<endl;
	//for(int i=1;i<=n;i++){for(int j=0;j<=m;j++)cout<<pre[i][j]<<" ";cout<<endl;}
	ll p=calc(r,0,0,1);
	//decrement(l);
	ll q=calc(l,0,0,0);
	ll t=-1;
	for(int i=2;i<=n;i+=2)if(l[i]!=d+'0'){t=0;break;}
	if(t!=0)
	{
		t=0;
		for(int i=1;i<=n;i++)t=(t*10+l[i]-'0')%m;
		if(t!=0)t=0;
		else t=1;
	}
	//cout<<"p="<<p<<" q="<<q<<endl;
	cout<<(p-q-t+MOD)%MOD<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define N 2009
#define ll long long
#define MOD 1000000007
int m,d,n;
char l[N],r[N];
ll dp[2][N][N];
ll pre[N][N];
ll f[N];
inline void init()
{
	f[0]=1%m;
	for(int i=1;i<N-2;i++)f[i]=(f[i-1]*10)%m;
	memset(dp,-1,sizeof(dp));
	//memset(pre,-1,sizeof(pre));
	//precompute();
}
ll precompute()//int k,int mod,int i)//another dp
{
	pre[0][0]=1;
	for(int k=0;k<=9;k++)
	{
		if(k==d)continue;
		pre[1][k%m]++;
		pre[2][(k*10+d)%m]++;
	}
	for(int i=3;i<=n;i+=2)
	{
		for(int j=0;j<m;j++)//mod
		{
			for(int k=0;k<=9;k++)//dig
			{
				if(k==d)continue;
				if(pre[i-1][j])pre[i][(j*10+k)%m]+=pre[i-1][j];
				if(pre[i][j])pre[i+1][(j*100+k*10+d)%m]+=pre[i][j];
			}
			for(int k=0;k<=9;k++)
			{
				pre[i][k]%=MOD;
				pre[i+1][k]%=MOD;
			}
		}
	}
}
ll calc(char r[],int mod,int i,int ch)
{
	if(i>=n)return 0;
	if(dp[ch][mod][i]!=-1)return dp[ch][mod][i];
	dp[ch][mod][i]=0;
	if(i+2>n)
	{
		for(int j=(i==0?1:0);j<=9;j++)
		{
			if(j==d)continue;
			if(r[i+1]<j+'0')break;
			//cout<<"i="<<i<<" mod="<<mod<<" j="<<j<<endl;
			if((mod-(j*f[n-i-1])%m+m)%m==0)dp[ch][mod][i]++;
		}
		return (dp[ch][mod][i]%=MOD);
	}
	for(int j=(i==0?1:0);j<=9;j++)
	{
		if(j==d)continue;
		ll t=(mod-(j*f[n-i-1]+d*f[n-i-2])%m+m)%m;
		//cout<<"i="<<i<<" mod="<<mod<<" j="<<j<<" aux="<<(j*f[n-i-1]+d*f[n-i-2])<<" t="<<t;
		if(r[i+2]==d+'0' && r[i+1]==j+'0'){//cout<<endl<<"new calc"<<endl;
		dp[ch][mod][i]+=calc(r,t,i+2,ch);}
		else if(r[i+2]<d+'0' && r[i+1]<=j+'0')break;
		else if(r[i+1]>=j+'0'){dp[ch][mod][i]+=pre[n-i-2][t];
		//cout<<" pre[n-i-2][t]="<<pre[n-i-2][t]<<endl;
		}
		else break;
	}
	//cout<<"dp[ch][mod][i]="<<(dp[ch][mod][i]%=MOD)<<endl;
	return (dp[ch][mod][i]%=MOD);
}
int main()
{
	cin>>m>>d;
	cin>>l+1>>r+1;
	//cout<<"l="<<l+1<<endl<<"r="<<r+1<<endl;
	n=strlen(l+1);
	init();
	//cout<<"ll"<<endl;
	precompute();
	//cout<<"n="<<n<<endl;
	//for(int i=1;i<=n;i++){
	//for(int j=0;j<=m;j++)cout<<pre[i][j]<<" ";cout<<endl;}
	ll p=calc(r,0,0,1);
	//decrement(l);
	ll q=calc(l,0,0,0);
	ll t=-1;
	for(int i=2;i<=n;i+=2)if(l[i]!=d+'0'){t=0;break;}
	if(t!=0)
	{
		t=0;
		for(int i=1;i<=n;i++)t=(t*10+l[i]-'0')%m;
		if(t!=0)t=0;
		else t=1;
	}
	cout<<(p-q-t+MOD)%MOD<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define N 2009
#define ll long long
#define MOD 1000000007
int m,d,n;
char l[N],r[N];
ll dp[2][N][N];
ll pre[N][N];
ll f[N];
inline void init()
{
	f[0]=1%m;
	for(int i=1;i<N-2;i++)f[i]=(f[i-1]*10)%m;
	memset(dp,-1,sizeof(dp));
	//memset(pre,-1,sizeof(pre));
	//precompute();
}
ll precompute()//int k,int mod,int i)//another dp
{
	pre[0][0]=1;
	for(int k=0;k<=9;k++)
	{
		if(k==d)continue;
		pre[1][k%m]++;
		pre[2][(k*10+d)%m]++;
	}
	for(int i=3;i<=n;i+=2)
	{
		for(int j=0;j<m;j++)//mod
		{
			if(pre[i-1][j])
			for(int k=0;k<=9;k++)//dig
			{
				if(k==d)continue;
				pre[i][(j*10+k)%m]+=pre[i-1][j];
			}
		}
		for(int j=0;j<m;j++)//mod
		{
			if(pre[i][j])
			//for(int k=0;k<=9;k++)//dig
			{
				pre[i+1][(j*10+d)%m]+=pre[i][j];
			}
		}
		for(int j=0;j<m;j++)
		{
			pre[i][j]%=MOD;
			pre[i+1][j]%=MOD;
		}
	}
}
ll calc(char r[],int mod,int i,int ch)
{
	//if(i==n)return 1;
	if(i>=n)return 0;
	if(dp[ch][mod][i]!=-1)return dp[ch][mod][i];
	dp[ch][mod][i]=0;
	if(i+2>n)
	{
		for(int j=(i==0?1:0);j<=9;j++)
		{
			if(j==d)continue;
			if(r[i+1]<j+'0')break;
			//cout<<"i="<<i<<" mod="<<mod<<" j="<<j<<endl;
			if((mod-(j*f[n-i-1])%m+m)%m==0)dp[ch][mod][i]++;
		}
		return (dp[ch][mod][i]%=MOD);
	}
	for(int j=(i==0?1:0);j<=9;j++)
	{
		if(j==d)continue;
		ll t=(mod-(j*f[n-i-1]+d*f[n-i-2])%m+m)%m;
		//cout<<"i="<<i<<" mod="<<mod<<" j="<<j<<" aux="<<(j*f[n-i-1]+d*f[n-i-2])<<" t="<<t;
		if(r[i+2]==d+'0' && r[i+1]==j+'0'){//cout<<endl<<"new calc"<<endl;
		dp[ch][mod][i]+=calc(r,t,i+2,ch);}
		else if(r[i+2]<d+'0' && r[i+1]<=j+'0')break;
		else if(r[i+1]>=j+'0'){dp[ch][mod][i]+=pre[n-i-2][t];
		//cout<<" pre[n-i-2][t]="<<pre[n-i-2][t]<<endl;
		}
		else break;
	}
	//cout<<"dp[ch][mod][i]="<<(dp[ch][mod][i]%=MOD)<<endl;
	return (dp[ch][mod][i]%=MOD);
}
int main()
{
	cin>>m>>d;
	cin>>l+1>>r+1;
	//cout<<"l="<<l+1<<endl<<"r="<<r+1<<endl;
	n=strlen(l+1);
	init();
	//cout<<"ll"<<endl;
	precompute();
	//cout<<"n="<<n<<endl;
	//for(int i=1;i<=n;i++){for(int j=0;j<=m;j++)cout<<pre[i][j]<<" ";cout<<endl;}
	ll p=calc(r,0,0,1);
	//decrement(l);
	ll q=calc(l,0,0,0);
	ll t=-1;
	for(int i=2;i<=n;i+=2)if(l[i]!=d+'0'){t=0;break;}
	if(t!=0)
	{
		t=0;
		for(int i=1;i<=n;i++)t=(t*10+l[i]-'0')%m;
		if(t!=0)t=0;
		else t=1;
	}
	//cout<<"p="<<p<<" q="<<q<<" t="<<t<<endl;
	cout<<(p-q+t+MOD)%MOD<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define N 2009
#define ll long long
#define MOD 1000000007
int m,d,n;
char l[N],r[N];
ll dp[2][N][N];
ll pre[N][N];
ll f[N];
inline void init()
{
	f[0]=1%m;
	for(int i=1;i<N-2;i++)f[i]=(f[i-1]*10)%m;
	memset(dp,-1,sizeof(dp));
	//memset(pre,-1,sizeof(pre));
	//precompute();
}
ll precompute()//int k,int mod,int i)//another dp
{
	pre[0][0]=1;
	for(int k=0;k<=9;k++)
	{
		if(k==d)continue;
		pre[1][k%m]++;
		pre[2][(k*10+d)%m]++;
	}
	for(int i=3;i<=n;i+=2)
	{
		for(int j=0;j<m;j++)//mod
		{
			if(pre[i-1][j])
			for(int k=0;k<=9;k++)//dig
			{
				if(k==d)continue;
				pre[i][(j*10+k)%m]+=pre[i-1][j];
			}
		}
		for(int j=0;j<m;j++)//mod
		{
			if(pre[i][j])
			//for(int k=0;k<=9;k++)//dig
			{
				pre[i+1][(j*10+d)%m]+=pre[i][j];
			}
		}
		for(int j=0;j<m;j++)
		{
			pre[i][j]%=MOD;
			pre[i+1][j]%=MOD;
		}
	}
}
ll calc(char r[],int mod,int i,int ch)
{
	if(i==n && mod==0)return 1;
	if(i>=n)return 0;
	if(dp[ch][mod][i]!=-1)return dp[ch][mod][i];
	dp[ch][mod][i]=0;
	if(i+2>n)
	{
		for(int j=(i==0?1:0);j<=9;j++)
		{
			if(j==d)continue;
			if(r[i+1]<j+'0')break;
			//cout<<"i="<<i<<" mod="<<mod<<" j="<<j<<endl;
			if((mod-(j*f[n-i-1])%m+m)%m==0)dp[ch][mod][i]++;
		}
		return (dp[ch][mod][i]%=MOD);
	}
	for(int j=(i==0?1:0);j<=9;j++)
	{
		if(j==d)continue;
		ll t=(mod-(j*f[n-i-1]+d*f[n-i-2])%m+m)%m;
		//cout<<"i="<<i<<" mod="<<mod<<" j="<<j<<" aux="<<(j*f[n-i-1]+d*f[n-i-2])<<" t="<<t;
		if(r[i+2]==d+'0' && r[i+1]==j+'0'){//cout<<endl<<"new calc"<<endl;
		dp[ch][mod][i]+=calc(r,t,i+2,ch);}
		else if(r[i+2]<d+'0' && r[i+1]<=j+'0')break;
		else if(r[i+1]>=j+'0'){dp[ch][mod][i]+=pre[n-i-2][t];
		//cout<<" pre[n-i-2][t]="<<pre[n-i-2][t]<<endl;
		}
		else break;
	}
	//cout<<"dp[ch][mod][i]="<<(dp[ch][mod][i]%=MOD)<<endl;
	return (dp[ch][mod][i]%=MOD);
}
int main()
{
	cin>>m>>d;
	cin>>l+1>>r+1;
	//cout<<"l="<<l+1<<endl<<"r="<<r+1<<endl;
	n=strlen(l+1);
	init();
	//cout<<"ll"<<endl;
	precompute();
	//cout<<"n="<<n<<endl;
	//for(int i=1;i<=n;i++){for(int j=0;j<=m;j++)cout<<pre[i][j]<<" ";cout<<endl;}
	ll p=calc(r,0,0,1);
	//decrement(l);
	ll q=calc(l,0,0,0);
	ll t=-1;
	for(int i=1;i<=n;i+=2)if(l[i]==d+'0' || (i+1<=n && l[i+1]!=d+'0')){t=0;break;}
	if(t!=0)
	{
		t=0;
		for(int i=1;i<=n;i++)t=(t*10+l[i]-'0')%m;
		if(t!=0)t=0;
		else t=1;
	}
	//cout<<"p="<<p<<" q="<<q<<" t="<<t<<endl;
	cout<<(p-q+t+MOD)%MOD<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define N 2009
#define ll long long
#define MOD 1000000007
int m,d,n;
char l[N],r[N];
ll dp[2][N][N];
ll pre[N][N];
ll f[N];
inline void init()
{
	f[0]=1%m;
	for(int i=1;i<N-2;i++)f[i]=(f[i-1]*10)%m;
	memset(dp,-1,sizeof(dp));
	//memset(pre,-1,sizeof(pre));
	//precompute();
}
ll precompute()//int k,int mod,int i)//another dp
{
	pre[0][0]=1;
	for(int k=0;k<=9;k++)
	{
		if(k==d)continue;
		pre[1][k%m]++;
		pre[2][(k*10+d)%m]++;
	}
	for(int i=3;i<=n;i+=2)
	{
		for(int j=0;j<m;j++)//mod
		{
			if(pre[i-1][j])
			for(int k=0;k<=9;k++)//dig
			{
				if(k==d)continue;
				pre[i][(j*10+k)%m]+=pre[i-1][j];
			}
		}
		for(int j=0;j<m;j++)//mod
		{
			if(pre[i][j])
			//for(int k=0;k<=9;k++)//dig
			{
				pre[i+1][(j*10+d)%m]+=pre[i][j];
			}
		}
		for(int j=0;j<m;j++)
		{
			pre[i][j]%=MOD;
			pre[i+1][j]%=MOD;
		}
	}
}
ll calc(char r[],int mod,int i,int ch)
{
	//if(i==n)return 1;
	if(i>=n)return 0;
	if(dp[ch][mod][i]!=-1)return dp[ch][mod][i];
	dp[ch][mod][i]=0;
	if(i+2>n)
	{
		for(int j=(i==0?1:0);j<=9;j++)
		{
			if(j==d)continue;
			if(r[i+1]<j+'0')break;
			//cout<<"i="<<i<<" mod="<<mod<<" j="<<j<<endl;
			if((mod-(j*f[n-i-1])%m+m)%m==0)dp[ch][mod][i]++;
		}
		return (dp[ch][mod][i]%=MOD);
	}
	for(int j=(i==0?1:0);j<=9;j++)
	{
		if(j==d)continue;
		ll t=(mod-(j*f[n-i-1]+d*f[n-i-2])%m+m)%m;
		//cout<<"i="<<i<<" mod="<<mod<<" j="<<j<<" aux="<<(j*f[n-i-1]+d*f[n-i-2])<<" t="<<t;
		if(r[i+2]==d+'0' && r[i+1]==j+'0'){//cout<<endl<<"new calc"<<endl;
		dp[ch][mod][i]+=calc(r,t,i+2,ch);}
		else if(r[i+2]<d+'0' && r[i+1]<=j+'0')break;
		else if(r[i+1]>=j+'0'){dp[ch][mod][i]+=pre[n-i-2][t];
		//cout<<" pre[n-i-2][t]="<<pre[n-i-2][t]<<endl;
		}
		else break;
	}
	//cout<<"dp[ch][mod][i]="<<(dp[ch][mod][i]%=MOD)<<endl;
	return (dp[ch][mod][i]%=MOD);
}
int main()
{
	cin>>m>>d;
	cin>>l+1>>r+1;
	//cout<<"l="<<l+1<<endl<<"r="<<r+1<<endl;
	n=strlen(l+1);
	init();
	//cout<<"ll"<<endl;
	precompute();
	//cout<<"n="<<n<<endl;
	//for(int i=1;i<=n;i++){for(int j=0;j<=m;j++)cout<<pre[i][j]<<" ";cout<<endl;}
	ll p=calc(r,0,0,1);
	//decrement(l);
	ll q=calc(l,0,0,0);
	ll t=-1;
	for(int i=1;i<=n;i+=2)if(l[i]==d+'0' || (i+1<=n && l[i+1]!=d+'0')){t=0;break;}
	if(t!=0)
	{
		t=0;
		for(int i=1;i<=n;i++)t=(t*10+l[i]-'0')%m;
		if(t!=0)t=0;
		else t=1;
	}
	//cout<<"p="<<p<<" q="<<q<<" t="<<t<<endl;
	cout<<(p-q+t+MOD)%MOD<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define N 2009
#define ll long long
#define MOD 1000000007
int m,d,n;
char l[N],r[N];
ll dp[2][N][N];
ll pre[N][N];
ll f[N];
inline void init()
{
	f[0]=1%m;
	for(int i=1;i<N-2;i++)f[i]=(f[i-1]*10)%m;
	memset(dp,-1,sizeof(dp));
	//memset(pre,-1,sizeof(pre));
	//precompute();
}
ll precompute()//int k,int mod,int i)//another dp
{
	pre[0][0]=1;
	for(int k=0;k<=9;k++)
	{
		if(k==d)continue;
		pre[1][k%m]++;
		pre[2][(k*10+d)%m]++;
	}
	for(int i=3;i<=n;i+=2)
	{
		for(int j=0;j<m;j++)//mod
		{
			if(pre[i-1][j])
			for(int k=0;k<=9;k++)//dig
			{
				if(k==d)continue;
				pre[i][(j*10+k)%m]+=pre[i-1][j];
			}
		}
		for(int j=0;j<m;j++)//mod
		{
			if(pre[i][j])
			//for(int k=0;k<=9;k++)//dig
			{
				pre[i+1][(j*10+d)%m]+=pre[i][j];
			}
		}
		for(int j=0;j<m;j++)
		{
			pre[i][j]%=MOD;
			pre[i+1][j]%=MOD;
		}
	}
}
ll calc(char r[],int mod,int i,int ch)
{
	if(i==n)return 1;
	//if(i>=n)return 0;
	if(dp[ch][mod][i]!=-1)return dp[ch][mod][i];
	dp[ch][mod][i]=0;
	if(i+2>n)
	{
		for(int j=(i==0?1:0);j<=9;j++)
		{
			if(j==d)continue;
			if(r[i+1]<j+'0')break;
			//cout<<"i="<<i<<" mod="<<mod<<" j="<<j<<endl;
			if((mod-(j*f[n-i-1])%m+m)%m==0)dp[ch][mod][i]++;
		}
		return (dp[ch][mod][i]%=MOD);
	}
	for(int j=(i==0?1:0);j<=9;j++)
	{
		if(j==d)continue;
		ll t=(mod-(j*f[n-i-1]+d*f[n-i-2])%m+m)%m;
		//cout<<"i="<<i<<" mod="<<mod<<" j="<<j<<" aux="<<(j*f[n-i-1]+d*f[n-i-2])<<" t="<<t;
		if(r[i+2]==d+'0' && r[i+1]==j+'0'){//cout<<endl<<"new calc"<<endl;
		dp[ch][mod][i]+=calc(r,t,i+2,ch);}
		else if(r[i+2]<d+'0' && r[i+1]<=j+'0')break;
		else if(r[i+1]>=j+'0'){dp[ch][mod][i]+=pre[n-i-2][t];
		//cout<<" pre[n-i-2][t]="<<pre[n-i-2][t]<<endl;
		}
		else break;
	}
	//cout<<"dp[ch][mod][i]="<<(dp[ch][mod][i]%=MOD)<<endl;
	return (dp[ch][mod][i]%=MOD);
}
int main()
{
	cin>>m>>d;
	cin>>l+1>>r+1;
	//cout<<"l="<<l+1<<endl<<"r="<<r+1<<endl;
	n=strlen(l+1);
	init();
	//cout<<"ll"<<endl;
	precompute();
	//cout<<"n="<<n<<endl;
	//for(int i=1;i<=n;i++){for(int j=0;j<=m;j++)cout<<pre[i][j]<<" ";cout<<endl;}
	ll p=calc(r,0,0,1);
	//decrement(l);
	ll q=calc(l,0,0,0);
	ll t=-1;
	for(int i=2;i<=n;i+=2)if(l[i]!=d+'0'){t=0;break;}
	if(t!=0)
	{
		t=0;
		for(int i=1;i<=n;i++)t=(t*10+l[i]-'0')%m;
		if(t!=0)t=0;
		else t=1;
	}
	//cout<<"p="<<p<<" q="<<q<<" t="<<t<<endl;
	cout<<(p-q+t+MOD)%MOD<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ii, ii> iii;
const int MOD = 1e9 + 7;
const ld E = 1e-9;
#define null NULL
#define ms(x) memset(x, 0, sizeof(x))
#define endl "\n"
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define _read(x) freopen(x, "r", stdin)
#define _write(x) freopen(x, "w", stdout)
#define files(x) _read(x ".in"); _write(x ".out")
#define input _read("input.txt")
#define mod % MOD
template<typename T> inline T sqr(T t) {
	return t * t;
}
#ifdef LOCAL
//#define DEBUG
#endif

#ifdef DEBUG
#define dbg if(1)
#else
#define dbg if(0)
#endif

ll solve(string s, int m, int d, int t = 0) {
	int n = (int) s.size();
	ll dp[n][m];
	ms(dp);
	int v = s[0] - '0';
	for (int i = 1; i < v; i++) {
		if (d == i)
			continue;
		dp[0][i % m]++;
	}
	int w = (s[0] - '0') % m;
	bool ok = true;
	for (int i = 1; i < n; i++) {
		bool r = i % 2;
		if (r) {
			if (ok && s[i] - '0' > d){
				dbg cout << "inc " << i << " " << (w * 10 + d) << endl;
				dp[i][(w * 10 + d) % m]++;
			}
			for (int z = 0; z < m; z++)
				dp[i][(z * 10 + d) % m] += dp[i - 1][z];
			if (s[i] - '0' != d)
				ok = false;
		} else {
			for (int j = 0; j < 10; j++) {
				if (j == d)
					continue;
				for (int z = 0; z < m; z++) {
					dp[i][(z * 10 + j) % m] += dp[i - 1][z];
				}
			}
			if (ok) {
				for (int j = 0; j < s[i] - '0'; j++){
					if(j == d)
						continue;
					dbg cout << "+ " << (w * 10 + j) % m << endl;
					dp[i][(w * 10 + j) % m]++;
				}
				if(s[i] - '0' == d)
					ok = false;
			}
		}
		for (int z = 0; z < m; z++)
			dp[i][z] = dp[i][z]mod;
		w = (w * 10 + (s[i] - '0')) % m;
		dbg cout << w << endl;
	}
	dbg
		cout << s << endl;
	dbg
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				cout << dp[i][j] << " ";
			}
			cout << endl;
		}
	if(ok && w == 0){
		dp[n - 1][0] = (dp[n - 1][0] + 1) mod;
	}
	dbg cout << ok << endl;
	dbg cout << "res for " << s << " = " << dp[n - 1][0] << endl;
	return dp[n - 1][0];
}

void dec(string &s) {
	for (int i = (int) s.size() - 1; i >= 0; i--) {
		if (s[i] == '0') {
			s[i] = '9';
		} else {
			s[i]--;
			break;
		}
	}
	if (s[0] == '0') {
		s.erase(s.begin());
	}
}

void inc(string &s) {
	for (int i = (int) s.size() - 1; i >= 0; i--) {
		if (s[i] == '9') {
			s[i] = '0';
		} else {
			s[i]++;
			break;
		}
	}
}

int get_mod(string s, int m) {
	int ans = 0;
	for (int i = 0; i < (int) s.size(); i++)
		ans = (ans * 10 + s[i] - '0') % m;
	return ans;
}

bool check(string s, int q) {
	for (int i = 1; i < (int) s.size(); i += 2)
		if (s[i] - '0' != q)
			return false;
	for (int i = 0; i < (int) s.size(); i += 2)
		if (s[i] - '0' == q)
			return false;
	return true;
}

ll solve_long(string s1, string s2, int m, int d, bool bol = true) {
	int ans = 0;
	while (s1 != s2) {
		if (get_mod(s1, m) == 0 && check(s1, d)) {
			dbg if(bol) cout << s1 << endl;
			ans++;
		}
		inc(s1);
	}
	if (get_mod(s1, m) == 0 && check(s1, d)) {
		ans++;
		dbg if(bol) cout << s1 << endl;
	}
	return ans;
}

int main() {

	sync;
	cout.precision(12);
	cout << fixed;
	srand(time(NULL));

#ifdef LOCAL
	input;
#else

#endif

	int n, m;
	cin >> n >> m;

	string s1, s2;
	cin >> s1 >> s2;
#ifdef LOCAL
	{
		cout << "ans = " << solve_long(s1, s2, n, m) << endl;
		if(0) {
			string q = "1" + string((int) s1.size() - 1, '0');
			cout << q << endl;
			dec(s1);
			cout << solve_long(q, s1, n, m, false) << " " << solve_long(q, s2, n, m, false) << endl;
			inc(s1);
		}
	}
#endif
	if(s1 == "0") {
		cout << solve(s2, n, m);
	} else {
		dec(s1);
		if(s1.size() != s2.size()) {
			cout << solve(s2, n, m) << endl;
		} else {
			cout << (solve(s2, n, m) + MOD - solve(s1, n, m)) mod;
		}
	}

}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ii, ii> iii;
const int MOD = 1e9 + 7;
const ld E = 1e-9;
#define null NULL
#define ms(x) memset(x, 0, sizeof(x))
#define endl "\n"
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define _read(x) freopen(x, "r", stdin)
#define _write(x) freopen(x, "w", stdout)
#define files(x) _read(x ".in"); _write(x ".out")
#define input _read("input.txt")
#define mod % MOD
template<typename T> inline T sqr(T t) {
	return t * t;
}
#ifdef LOCAL
//#define DEBUG
#endif

#ifdef DEBUG
#define dbg if(1)
#else
#define dbg if(0)
#endif

ll solve(string s, int m, int d, int t = 0) {
	int n = (int) s.size();
	ll dp[n][m];
	ms(dp);
	if (t % 2 == 0) {
		int v = s[0] - '0';
		for (int i = 1; i <= v; i++) {
			if (d == i)
				continue;
			dp[0][i % m]++;
		}
	} else {
		int v = s[0] - '0';
		if (v < d)
			return 0;
		dp[0][d % m]++;
	}
	int w = (s[0] - '0') % m;
	bool ok = (s[0] != '1');
	for (int i = 1; i < n; i++) {
		bool r = (i + t) % 2;
		w = (w * 10 + (s[i] - '0')) % m;
		if (r) {
			for (int z = 0; z < m; z++)
				dp[i][(z * 10 + d) % m] += dp[i - 1][z];
		} else {
			if (ok) {
				for (int j = 0; j < 10; j++) {
					if (j == d)
						continue;
					for (int z = 0; z < m; z++) {
						dp[i][(z * 10 + j) % m] += dp[i - 1][z];
					}
				}
			}
			dp[i][w]++;
			ok |= (s[i] != '1');
		}
		for (int z = 0; z < m; z++)
			dp[i][z] = dp[i][z]mod;
	}
	dbg cout << s << endl;
	dbg for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			cout << dp[i][j] << " ";
		}
		cout << endl;
	}
	return dp[n - 1][0];
}

void dec(string &s) {
	for (int i = (int) s.size() - 1; i >= 0; i--) {
		if (s[i] == '0') {
			s[i] = '9';
		} else {
			s[i]--;
			break;
		}
	}
	if (s[0] == '0') {
		s.erase(s.begin());
	}
}

int main() {

	sync;
	cout.precision(12);
	cout << fixed;
	srand(time(NULL));

#ifdef LOCAL
	input;
#else

#endif

	int n, m;
	cin >> n >> m;

	string s1, s2;
	cin >> s1 >> s2;

	if(s1 == "0") {
		cout << solve(s2, n, m);
	} else {
		dec(s1);
		if(s1.size() != s2.size()) {
			cout << solve(s2, n, m) << endl;
		} else {
			cout << (solve(s2, n, m) + MOD - solve(s1, n, m)) mod;
		}
	}

}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ii, ii> iii;
const int MOD = 1e9 + 7;
const ld E = 1e-9;
#define null NULL
#define ms(x) memset(x, 0, sizeof(x))
#define endl "\n"
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define _read(x) freopen(x, "r", stdin)
#define _write(x) freopen(x, "w", stdout)
#define files(x) _read(x ".in"); _write(x ".out")
#define input _read("input.txt")
#define mod % MOD
template<typename T> inline T sqr(T t) {
	return t * t;
}
#ifdef LOCAL
//#define DEBUG
#endif

#ifdef DEBUG
#define dbg if(1)
#else
#define dbg if(0)
#endif

ll solve(string s, int m, int d, int t = 0) {
	int n = (int) s.size();
	ll dp[n][m];
	ms(dp);
	int v = s[0] - '0';
	for (int i = 1; i < v; i++) {
		if (d == i)
			continue;
		dp[0][i % m]++;
	}
	int w = (s[0] - '0') % m;
	bool ok = true;
	for (int i = 1; i < n; i++) {
		bool r = i % 2;
		if (r) {
			if (ok && s[i] - '0' > d){
				dbg cout << "inc " << i << " " << (w * 10 + d) << endl;
				dp[i][(w * 10 + d) % m]++;
			}
			for (int z = 0; z < m; z++)
				dp[i][(z * 10 + d) % m] += dp[i - 1][z];
			if (s[i] - '0' != d)
				ok = false;
		} else {
			for (int j = 0; j < 10; j++) {
				if (j == d)
					continue;
				for (int z = 0; z < m; z++) {
					dp[i][(z * 10 + j) % m] += dp[i - 1][z];
				}
			}
			if (ok) {
				for (int j = 0; j < s[i] - '0'; j++){
					if(j == d)
						continue;
					dbg cout << "+ " << (w * 10 + j) % m << endl;
					dp[i][(w * 10 + j) % m]++;
				}
			}
		}
		for (int z = 0; z < m; z++)
			dp[i][z] = dp[i][z]mod;
		w = (w * 10 + (s[i] - '0')) % m;
		dbg cout << w << endl;
	}
	dbg
		cout << s << endl;
	dbg
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				cout << dp[i][j] << " ";
			}
			cout << endl;
		}
	return dp[n - 1][0];
}

void dec(string &s) {
	for (int i = (int) s.size() - 1; i >= 0; i--) {
		if (s[i] == '0') {
			s[i] = '9';
		} else {
			s[i]--;
			break;
		}
	}
	if (s[0] == '0') {
		s.erase(s.begin());
	}
}

void inc(string &s) {
	for (int i = (int) s.size() - 1; i >= 0; i--) {
		if (s[i] == '9') {
			s[i] = '0';
		} else {
			s[i]++;
			break;
		}
	}
}

int get_mod(string s, int m) {
	int ans = 0;
	for (int i = 0; i < (int) s.size(); i++)
		ans = (ans * 10 + s[i] - '0') % m;
	return ans;
}

bool check(string s, int q) {
	for (int i = 1; i < (int) s.size(); i += 2)
		if (s[i] - '0' != q)
			return false;
	for (int i = 0; i < (int) s.size(); i += 2)
		if (s[i] - '0' == q)
			return false;
	return true;
}

ll solve_long(string s1, string s2, int m, int d, bool bol = true) {
	int ans = 0;
	while (s1 != s2) {
		if (get_mod(s1, m) == 0 && check(s1, d)) {
			dbg if(bol) cout << s1 << endl;
			ans++;
		}
		inc(s1);
	}
	if (get_mod(s1, m) == 0 && check(s1, d)) {
		ans++;
		dbg if(bol) cout << s1 << endl;
	}
	return ans;
}

int main() {

	sync;
	cout.precision(12);
	cout << fixed;
	srand(time(NULL));

#ifdef LOCAL
	input;
#else

#endif

	int n, m;
	cin >> n >> m;

	string s1, s2;
	cin >> s1 >> s2;
#ifdef LOCAL
	{
		cout << "ans = " << solve_long(s1, s2, n, m) << endl;
		if(0) {
			string q = "1" + string((int) s1.size() - 1, '0');
			cout << q << endl;
			dec(s1);
			cout << solve_long(q, s1, n, m, false) << " " << solve_long(q, s2, n, m, false) << endl;
			inc(s1);
		}
	}
#endif
	if(s1 == "0") {
		cout << solve(s2, n, m);
	} else {
		dec(s1);
		if(s1.size() != s2.size()) {
			cout << solve(s2, n, m) << endl;
		} else {
			cout << (solve(s2, n, m) + MOD - solve(s1, n, m)) mod;
		}
	}

}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ii, ii> iii;
const int MOD = 1e9 + 7;
const ld E = 1e-9;
#define null NULL
#define ms(x) memset(x, 0, sizeof(x))
//#define endl "\n"
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define _read(x) freopen(x, "r", stdin)
#define _write(x) freopen(x, "w", stdout)
#define files(x) _read(x ".in"); _write(x ".out")
#define input _read("input.txt")
#define mod % MOD
template<typename T> inline T sqr(T t) {
	return t * t;
}
#ifdef LOCAL
//#define DEBUG
#endif

#ifdef DEBUG
#define dbg if(1)
#else
#define dbg if(0)
#endif

ll solve(string s, int m, int d, int t = 0) {
	int n = (int) s.size();
	ll dp[n][m];
	ms(dp);
	int v = s[0] - '0';
	for (int i = 1; i < v; i++) {
		if (d == i)
			continue;
		dp[0][i % m]++;
	}
	int w = (s[0] - '0') % m;
	bool ok = s[0] - '0' != d;
	for (int i = 1; i < n; i++) {
		bool r = i % 2;
		if (r) {
			if (ok && s[i] - '0' > d) {
				dbg
					cout << "inc " << i << " " << (w * 10 + d) << endl;
				dp[i][(w * 10 + d) % m]++;
			}
			for (int z = 0; z < m; z++)
				dp[i][(z * 10 + d) % m] += dp[i - 1][z];
			if (s[i] - '0' != d)
				ok = false;
		} else {
			for (int j = 0; j < 10; j++) {
				if (j == d)
					continue;
				for (int z = 0; z < m; z++) {
					dp[i][(z * 10 + j) % m] += dp[i - 1][z];
				}
			}
			if (ok) {
				for (int j = 0; j < s[i] - '0'; j++) {
					if (j == d)
						continue;
					dbg
						cout << "+ " << (w * 10 + j) % m << endl;
					dp[i][(w * 10 + j) % m]++;
				}
				if (s[i] - '0' == d)
					ok = false;
			}
		}
		for (int z = 0; z < m; z++)
			dp[i][z] = dp[i][z]mod;
		w = (w * 10 + (s[i] - '0')) % m;
		dbg
			cout << w << endl;
	}
	dbg
		cout << s << endl;
	dbg
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				cout << dp[i][j] << " ";
			}
			cout << endl;
		}
	if (ok && w == 0) {
		dp[n - 1][0] = (dp[n - 1][0] + 1)mod;
	}
	dbg
		cout << ok << endl;
	dbg
		cout << "res for " << s << " = " << dp[n - 1][0] << endl;
	return dp[n - 1][0];
}

void dec(string &s) {
	for (int i = (int) s.size() - 1; i >= 0; i--) {
		if (s[i] == '0') {
			s[i] = '9';
		} else {
			s[i]--;
			break;
		}
	}
	if (s[0] == '0') {
		s.erase(s.begin());
	}
}

void inc(string &s) {
	for (int i = (int) s.size() - 1; i >= 0; i--) {
		if (s[i] == '9') {
			s[i] = '0';
		} else {
			s[i]++;
			break;
		}
	}
}

int get_mod(string s, int m) {
	int ans = 0;
	for (int i = 0; i < (int) s.size(); i++)
		ans = (ans * 10 + s[i] - '0') % m;
	return ans;
}

bool check(string s, int q) {
	for (int i = 1; i < (int) s.size(); i += 2)
		if (s[i] - '0' != q)
			return false;
	for (int i = 0; i < (int) s.size(); i += 2)
		if (s[i] - '0' == q)
			return false;
	return true;
}

ll solve_long(string s1, string s2, int m, int d, bool bol = true) {
	int ans = 0;
	while (s1 != s2) {
		if (get_mod(s1, m) == 0 && check(s1, d)) {
			dbg
				if (bol)
					cout << s1 << endl;
			ans++;
		}
		inc(s1);
	}
	if (get_mod(s1, m) == 0 && check(s1, d)) {
		ans++;
		dbg
			if (bol)
				cout << s1 << endl;
	}
	return ans;
}

bool _less(string s1, string s2) {
	for (int i = 0; i < (int) s1.size(); i++)
		if (s1[i] != s2[i])
			return s1[i] < s2[i];
	return false;
}

string get_rand(int n) {
	string ans;
	ans += char(rand() % 9 + '1');
	for (int i = 1; i < n; i++)
		ans += char(rand() % 10 + '0');
	return ans;
}

int main() {

	sync;
	cout.precision(12);
	cout << fixed;
	srand(time(NULL));

#ifdef LOCAL
	input;
#else

#endif

	int n, m;
	cin >> n >> m;

	string s1, s2;
	cin >> s1 >> s2;
#ifdef LOCAL
	{
		cout << "ans = " << solve_long(s1, s2, n, m) << endl;
		if(1) {
			string q = "1" + string((int) s1.size() - 1, '0');
			dec(s1);
			cout << solve_long(q, s1, n, m, false) << " " << solve_long(q, s2, n, m, false) << endl;
			inc(s1);
		}
	}
#endif
	if(s1 == "0") {
		cout << solve(s2, n, m);
	} else {
		dec(s1);
		if(s1.size() != s2.size()) {
			cout << solve(s2, n, m) << endl;
		} else {
			cout << (solve(s2, n, m) + MOD - solve(s1, n, m)) mod;
		}
	}

}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ii, ii> iii;
const int MOD = 1e9 + 7;
const ld E = 1e-9;
#define null NULL
#define ms(x) memset(x, 0, sizeof(x))
#define endl "\n"
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define _read(x) freopen(x, "r", stdin)
#define _write(x) freopen(x, "w", stdout)
#define files(x) _read(x ".in"); _write(x ".out")
#define input _read("input.txt")
#define mod % MOD
template<typename T> inline T sqr(T t) {
	return t * t;
}
#ifdef LOCAL
//#define DEBUG
#endif

#ifdef DEBUG
#define dbg if(1)
#else
#define dbg if(0)
#endif

ll solve(string s, int m, int d, int t = 0) {
	int n = (int) s.size();
	ll dp[n][m];
	ms(dp);
	int v = s[0] - '0';
	for (int i = 1; i < v; i++) {
		if (d == i)
			continue;
		dp[0][i % m]++;
	}
	int w = (s[0] - '0') % m;
	bool ok = true;
	for (int i = 1; i < n; i++) {
		bool r = i % 2;
		if (r) {
			if (ok && s[i] - '0' > d){
				dbg cout << "inc " << i << " " << (w * 10 + d) << endl;
				dp[i][(w * 10 + d) % m]++;
			}
			for (int z = 0; z < m; z++)
				dp[i][(z * 10 + d) % m] += dp[i - 1][z];
			if (s[i] - '0' != d)
				ok = false;
		} else {
			for (int j = 0; j < 10; j++) {
				if (j == d)
					continue;
				for (int z = 0; z < m; z++) {
					dp[i][(z * 10 + j) % m] += dp[i - 1][z];
				}
			}
			if (ok) {
				for (int j = 0; j < s[i] - '0'; j++){
					if(j == d)
						continue;
					dbg cout << "+ " << (w * 10 + j) % m << endl;
					dp[i][(w * 10 + j) % m]++;
				}
				if(s[i] - '0' == d)
					ok = false;
			}
		}
		for (int z = 0; z < m; z++)
			dp[i][z] = dp[i][z]mod;
		w = (w * 10 + (s[i] - '0')) % m;
		dbg cout << w << endl;
	}
	dbg
		cout << s << endl;
	dbg
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				cout << dp[i][j] << " ";
			}
			cout << endl;
		}
	if(ok){
		dp[n - 1][0] = (dp[n - 1][0] + 1) mod;
	}
	dbg cout << ok << endl;
	dbg cout << "res for " << s << " = " << dp[n - 1][0] << endl;
	return dp[n - 1][0];
}

void dec(string &s) {
	for (int i = (int) s.size() - 1; i >= 0; i--) {
		if (s[i] == '0') {
			s[i] = '9';
		} else {
			s[i]--;
			break;
		}
	}
	if (s[0] == '0') {
		s.erase(s.begin());
	}
}

void inc(string &s) {
	for (int i = (int) s.size() - 1; i >= 0; i--) {
		if (s[i] == '9') {
			s[i] = '0';
		} else {
			s[i]++;
			break;
		}
	}
}

int get_mod(string s, int m) {
	int ans = 0;
	for (int i = 0; i < (int) s.size(); i++)
		ans = (ans * 10 + s[i] - '0') % m;
	return ans;
}

bool check(string s, int q) {
	for (int i = 1; i < (int) s.size(); i += 2)
		if (s[i] - '0' != q)
			return false;
	for (int i = 0; i < (int) s.size(); i += 2)
		if (s[i] - '0' == q)
			return false;
	return true;
}

ll solve_long(string s1, string s2, int m, int d, bool bol = true) {
	int ans = 0;
	while (s1 != s2) {
		if (get_mod(s1, m) == 0 && check(s1, d)) {
			dbg if(bol) cout << s1 << endl;
			ans++;
		}
		inc(s1);
	}
	if (get_mod(s1, m) == 0 && check(s1, d)) {
		ans++;
		dbg if(bol) cout << s1 << endl;
	}
	return ans;
}

int main() {

	sync;
	cout.precision(12);
	cout << fixed;
	srand(time(NULL));

#ifdef LOCAL
	input;
#else

#endif

	int n, m;
	cin >> n >> m;

	string s1, s2;
	cin >> s1 >> s2;
#ifdef LOCAL
	{
		cout << "ans = " << solve_long(s1, s2, n, m) << endl;
		if(0) {
			string q = "1" + string((int) s1.size() - 1, '0');
			cout << q << endl;
			dec(s1);
			cout << solve_long(q, s1, n, m, false) << " " << solve_long(q, s2, n, m, false) << endl;
			inc(s1);
		}
	}
#endif
	if(s1 == "0") {
		cout << solve(s2, n, m);
	} else {
		dec(s1);
		if(s1.size() != s2.size()) {
			cout << solve(s2, n, m) << endl;
		} else {
			cout << (solve(s2, n, m) + MOD - solve(s1, n, m)) mod;
		}
	}

}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ii, ii> iii;
const int MOD = 1e9 + 7;
const ld E = 1e-9;
#define null NULL
#define ms(x) memset(x, 0, sizeof(x))
#define endl "\n"
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define _read(x) freopen(x, "r", stdin)
#define _write(x) freopen(x, "w", stdout)
#define files(x) _read(x ".in"); _write(x ".out")
#define input _read("input.txt")
#define mod % MOD
template<typename T> inline T sqr(T t) {
	return t * t;
}
#ifdef LOCAL
#define DEBUG
#endif

#ifdef DEBUG
#define dbg if(1)
#else
#define dbg if(0)
#endif

ll solve(string s, int m, int d, int t = 0) {
	int n = (int) s.size();
	ll dp[n][m];
	ms(dp);
	int v = s[0] - '0';
	for (int i = 1; i < v; i++) {
		if (d == i)
			continue;
		dp[0][i % m]++;
	}
	int w = (s[0] - '0') % m;
	bool ok = true;
	for (int i = 1; i < n; i++) {
		bool r = i % 2;
		if (r) {
			if (ok && s[i] - '0' > d){
				dbg cout << "inc " << i << " " << (w * 10 + d) << endl;
				dp[i][(w * 10 + d) % m]++;
			}
			for (int z = 0; z < m; z++)
				dp[i][(z * 10 + d) % m] += dp[i - 1][z];
			if (s[i] - '0' != d)
				ok = false;
		} else {
			for (int j = 0; j < 10; j++) {
				if (j == d)
					continue;
				for (int z = 0; z < m; z++) {
					dp[i][(z * 10 + j) % m] += dp[i - 1][z];
				}
			}
			if (ok) {
				for (int j = 0; j < s[i] - '0'; j++){
					if(j == d)
						continue;
					dbg cout << "+ " << (w * 10 + j) % m << endl;
					dp[i][(w * 10 + j) % m]++;
				}
				if(s[i] - '0' == d)
					ok = false;
			}
		}
		for (int z = 0; z < m; z++)
			dp[i][z] = dp[i][z]mod;
		w = (w * 10 + (s[i] - '0')) % m;
		dbg cout << w << endl;
	}
	dbg
		cout << s << endl;
	dbg
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				cout << dp[i][j] << " ";
			}
			cout << endl;
		}
	return dp[n - 1][0];
}

void dec(string &s) {
	for (int i = (int) s.size() - 1; i >= 0; i--) {
		if (s[i] == '0') {
			s[i] = '9';
		} else {
			s[i]--;
			break;
		}
	}
	if (s[0] == '0') {
		s.erase(s.begin());
	}
}

void inc(string &s) {
	for (int i = (int) s.size() - 1; i >= 0; i--) {
		if (s[i] == '9') {
			s[i] = '0';
		} else {
			s[i]++;
			break;
		}
	}
}

int get_mod(string s, int m) {
	int ans = 0;
	for (int i = 0; i < (int) s.size(); i++)
		ans = (ans * 10 + s[i] - '0') % m;
	return ans;
}

bool check(string s, int q) {
	for (int i = 1; i < (int) s.size(); i += 2)
		if (s[i] - '0' != q)
			return false;
	for (int i = 0; i < (int) s.size(); i += 2)
		if (s[i] - '0' == q)
			return false;
	return true;
}

ll solve_long(string s1, string s2, int m, int d, bool bol = true) {
	int ans = 0;
	while (s1 != s2) {
		if (get_mod(s1, m) == 0 && check(s1, d)) {
			dbg if(bol) cout << s1 << endl;
			ans++;
		}
		inc(s1);
	}
	if (get_mod(s1, m) == 0 && check(s1, d)) {
		ans++;
		dbg if(bol) cout << s1 << endl;
	}
	return ans;
}

int main() {

	sync;
	cout.precision(12);
	cout << fixed;
	srand(time(NULL));

#ifdef LOCAL
	input;
#else

#endif

	int n, m;
	cin >> n >> m;

	string s1, s2;
	cin >> s1 >> s2;
#ifdef LOCAL
	{
		cout << "ans = " << solve_long(s1, s2, n, m) << endl;
		if(0) {
			string q = "1" + string((int) s1.size() - 1, '0');
			cout << q << endl;
			dec(s1);
			cout << solve_long(q, s1, n, m, false) << " " << solve_long(q, s2, n, m, false) << endl;
			inc(s1);
		}
	}
#endif
	if(s1 == "0") {
		cout << solve(s2, n, m);
	} else {
		dec(s1);
		if(s1.size() != s2.size()) {
			cout << solve(s2, n, m) << endl;
		} else {
			cout << (solve(s2, n, m) + MOD - solve(s1, n, m)) mod;
		}
	}

}


#include<bits/stdc++.h>
#define ll long long int
#define pii pair<ll,ll>
#define mp make_pair
#define pb push_back
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define M 500005
#define mod 1000000007
#define inf LLONG_MAX
using namespace std;
string s;
int n,m,k;
ll dp[2005][2005][2];
ll solve(ll i,ll rem,ll tight)
{
	if(i==n)
	{
		if(rem==0)
		return 1;
		else
		return 0;
	}
	if(dp[i][rem][tight]==-1)
	{
		dp[i][rem][tight]=0;
		if(i&1)
		{
			if(tight)
			{
				if(s[i]-'0'>k)
				dp[i][rem][tight]=solve(i+1,(10*rem+k)%m,0);
				else if(s[i]-'0'==k)
				dp[i][rem][tight]=solve(i+1,(10*rem+k)%m,1);
			}
			else
			dp[i][rem][tight]=solve(i+1,(10*rem+k)%m,0);
		}
		else
		{
			if(tight)
			{
				int j;
				for(j=0;j<(s[i]-'0');j++)
				{
					if(j!=k)
					{
						dp[i][rem][tight]+=solve(i+1,(10*rem+j)%m,0);
						dp[i][rem][tight]%=mod;
					}
				}
				if(j!=k)
				{
					dp[i][rem][tight]+=solve(i+1,(10*rem+j)%m,1);
					dp[i][rem][tight]%=mod;
				}
			}
			else
			{
				for(int j=0;j<10;j++)
				{
					if(j!=k)
					{
						dp[i][rem][tight]+=solve(i+1,(10*rem+j)%m,0);
						dp[i][rem][tight]%=mod;
					}
				}
			}
		}
	}
	return dp[i][rem][tight];
}
int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	ll t,q,i,j,x,y,z;
	string a,b;
	cin>>m>>k;
	cin>>a;
	cin>>b;
	z=0;
	int flag=1;
	n=a.length();
	for(i=0;i<n;i++)
	{
		if(i&1)
		{
			if(a[i]!=k+'0')
			flag=0;
		}
		else
		{
			if(a[i]==k+'0')
			flag=0;
		}
		z=(z*10+(a[i]-'0'));
		z%=m;
	}
	if(z!=0)
	flag=0;
	s=a;
	memset(dp,-1,sizeof dp);
	x=solve(0,0,1);
	s=b;
	memset(dp,-1,sizeof dp);
	y=solve(0,0,1);
	//cout<<x<<" "<<y<<" "<<flag<<"\n";
	x=y-x+mod+flag;
	x%=mod;
	cout<<x;
}

// Name - Hemant Chowdhury
// Arise, Awake And Stop Not Till The Goal Is Reached!
// If I fail,I will stand again;If I win,I will move farther