import java.util.ArrayList;
import java.util.Scanner;

public class Prob1 {

	public static void main(String[] args) {

		Scanner input = new Scanner(System.in);
		String place = input.next();
		char seat = place.charAt(place.length()-1);

		long row = Long.parseLong(place.substring(0 , place.length()-1));

		long seatN = getSeat(seat);
		long c = getC(row);

		long f ;

		if(c%2 == 0)
		{
			f =c*6 + c*2 + seatN;
		}
		else
			f = c*6 + c + seatN;

		System.out.println(f);

	}

	public static long getSeat(char seat)
	{
		if(seat == 'a')
			return 4;
		if(seat == 'b')
			return 5;
		if(seat == 'c')
			return 6;

		if(seat == 'd')
			return 3;
		if(seat == 'e')
			return 2;
		if(seat == 'f')
			return 1;

		return -1;
	}

	public static long getC(long row)
	{
		if(row%2 == 1)
		{
			long count = 0;
			long a = 1 ;
			long b = 3;

			while(a != row && b!= row)
			{
				a = b+2;
				b = a+2;
				count+=2;
			}

			return count;
		}

		long count = 1;
		long a = 2;
		long b = 4;

		while(a != row && b!= row)
		{
			a = b+2;
			b = a+2;
			count+=2;
		}

		return count;

	}

}


import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner inScanner = new Scanner(System.in);

		 	 int a  = inScanner.nextInt();
		 	 int b = inScanner.nextInt();

		 	 int fac_a[]  = new int[a];
		 	 int fac_b[] = new int[b];

		 	int commman[] = new int[Math.min(a, b)];

		 	 for (int i = 1; i <= fac_a.length; i++) {
				fac_a[i-1] = i;
			}
		 	for (int i = 1; i <= fac_b.length; i++) {
				fac_b[i-1] = i;
			}
		 	for (int i = 0; i < Math.min(a, b); i++) {

		 		if (fac_a[i]==fac_b[i]) {
					 commman[i] = fac_a[i];
				}

			}

		  int produ =1;

		  for (int i = 0; i < commman.length; i++) {
			produ*=commman[i];
		}
		  System.out.println(produ);

	}
}


import java.util.*;
        import java.io.IOException;
        import java.util.ArrayList;

public class Begin {
    public static void main(String[] args) throws IOException {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();

         int m = scan.nextInt();

         int min = 0, max = 0, index = 1;
         if(n>m){
             max = n;
             min = m;
         }
         else if(n<m){
             min = n;
             max = m;
         }
         else if (m == n){
             System.out.print(m);
         }
         for (int i = 1; i<=min; i++){
             index*= i;
         }
        System.out.print(index);


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ServalAndBonus solver = new ServalAndBonus();
        solver.solve(1, in, out);
        out.close();
    }

    static class ServalAndBonus {
        long MOD = 998244353;
        long[] inv = new long[5005];
        long[] pow = new long[5005];

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int N = in.nextInt();
            int K = in.nextInt();
            long l = in.nextInt();
            long invL = MathUtils.inverse(l, MOD);
            for (int i = 1; i < inv.length; i++) {
                inv[i] = MathUtils.inverse(i, MOD);
            }
            pow[0] = 1;
            for (int i = 1; i < pow.length; i++) {
                pow[i] = pow[i - 1] * l;
                pow[i] %= MOD;
            }
            long invL2 = (invL * invL) % MOD;
            long res = 0;
            long[] poly = new long[]{l, -1};
            long[] other = new long[]{(l * l) % MOD, -2 * l, 2};
            long[] cur = new long[4050];
            cur[0] = 1;
            for (int i = 0; i < N; i++) {
                for (int j = cur.length - 2; j >= 0; j--) {
                    cur[j] = cur[j] * poly[0] + (j - 1 >= 0 ? cur[j - 1] * poly[1] : 0);
                    cur[j] = MathUtils.mod(cur[j], MOD);
                    cur[j + 1] = cur[j];
                    cur[j] = 0;
                }
            }
            long comb = 1;
            for (int i = N; i >= K; i--) {
                long now = 0;
                for (int j = 0; j < cur.length; j++) {
                    now += ((pow[j + 1] * inv[j + 1]) % MOD) * cur[j];
                    now = MathUtils.mod(now, MOD);
                }
                now *= MathUtils.binPow(2, i, MOD);
                now %= MOD;
                now *= comb;
                now %= MOD;
                res += now;
                if (res >= MOD) {
                    res -= MOD;
                }
                for (int j = cur.length - 1; j >= 0; j--) {
                    cur[j] = cur[j] * other[0];
                    for (int k = 1; k <= 2; k++) {
                        if (j - k >= 0) {
                            cur[j] += cur[j - k] * other[k];
                        }
                    }
                    cur[j] = MathUtils.mod(cur[j], MOD);
                }
                long val = cur[cur.length - 1];
                for (int j = cur.length - 1; j >= 1; j--) {
                    cur[j] = -val;
                    val = cur[j - 1] + l * val;
                    val = MathUtils.mod(val, MOD);
                }
                for (int j = 0; j < cur.length - 1; j++) {
                    if (j + 2 >= cur.length) {
                        cur[j] = 0;
                    } else {
                        cur[j] = cur[j + 2];
                    }
                }
                comb *= inv[N - i + 1];
                comb %= MOD;
                comb *= i;
                comb %= MOD;
            }
            res *= MathUtils.binPow(invL2, N, MOD);
            res %= MOD;
            out.println(res);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }

    static class MathUtils {
        public static long inverse(long a, long mod) {
            long[] inv = extended_gcd(a, mod);
            if (inv[0] != 1) {
                return 0;
            } else {
                return (inv[1] + 2 * mod) % mod;
            }
        }

        public static long[] extended_gcd(long a, long b) {
            //three numbers, first is gcd, second is x, third is y
            if (a == 0) {
                return new long[]{b, 0, 1};
            }
            long[] next = extended_gcd(b % a, a);
            long tempX = next[1];
            next[1] = next[2] - (b / a) * next[1];
            next[2] = tempX;
            return next;
        }

        public static long binPow(long b, long p, long mod) {
            long res = 1;
            while (p > 0) {
                if ((p & 1) == 1) {
                    res *= b;
                    res %= mod;
                }
                b = b * b;
                p >>= 1;
                b %= mod;
            }
            return res;
        }

        public static long mod(long a, long mod) {
            return (a + (Math.abs(a) + mod - 1) / mod * mod) % mod;
        }

    }
}


import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.charset.Charset;
import java.util.Arrays;

public class CF1153F {
    public static void main(String[] args) throws Exception {
        boolean local = System.getProperty("ONLINE_JUDGE") == null;
        boolean async = false;

        Charset charset = Charset.forName("ascii");

        FastIO io = local ? new FastIO(new FileInputStream("D:\\DATABASE\\TESTCASE\\Code.in"), System.out, charset) : new FastIO(System.in, System.out, charset);
        Task task = new Task(io, new Debug(local));

        if (async) {
            Thread t = new Thread(null, task, "dalt", 1 << 27);
            t.setPriority(Thread.MAX_PRIORITY);
            t.start();
            t.join();
        } else {
            task.run();
        }

        if (local) {
            io.cache.append("\n\n--memory -- \n" + ((Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) >> 20) + "M");
        }

        io.flush();
    }

    public static class Task implements Runnable {
        final FastIO io;
        final Debug debug;
        int inf = (int) 1e8;
        int mod = 998244353;
        int[][][] mem;
        boolean[][][] visit;
        int l1;
        int l2;
        int l3;
        int n;
        int k;
        int time;

        public Task(FastIO io, Debug debug) {
            this.io = io;
            this.debug = debug;
        }

        @Override
        public void run() {
            solve();
        }

        public void solve() {
            n = io.readInt();
            k = io.readInt();
            int l = io.readInt();
            mem = new int[n + 1][n + 1][2];
            visit = new boolean[n + 1][n + 1][2];
            int meetCount = find(n, n, 1);

            int factorial = 1;
            for (int i = 2, until = 2 * n + 1; i <= until; i++) {
                factorial = mul(factorial, i);
            }
            int total = mul(factorial, Mathematics.inverse(Mathematics.pow(2, n, mod), mod));
            int probability = mul(meetCount, Mathematics.inverse(total, mod));
            int expectLength = mul(l, probability);
            io.cache.append(expectLength);
        }

        public int add(int a, int b) {
            return (a + b) % mod;
        }

        public int sub(int a, int b) {
            if (a >= b) {
                return a - b;
            }
            return a - b + mod;
        }

        public int mul(int a, int b) {
            return (int) (((long) a * b) % mod);
        }

        public int find(int i, int j, int x) {
            time++;
            if (i < 0 || i > n || j < 0 || j > n) {
                return 0;
            }
            if (i == 0 && j == 0 && x == 0) {
                return 1;
            }
            if (visit[i][j][x]) {
                return mem[i][j][x];
            }
            visit[i][j][x] = true;
            mem[i][j][x] = 0;
            if (i < j) {
                return 0;
            }
            if (x == 1) {
                mem[i][j][x] = (mem[i][j][x] + find(i, j, 0) * (i - j >= k ? 1 : 0)) % mod;
            }
            mem[i][j][x] = (int) ((mem[i][j][x] + (long) (n - i + 1) * find(i - 1, j, x)) % mod);
            mem[i][j][x] = (int)((mem[i][j][x] + (long)(i - j + 1) * find(i, j - 1, x)) % mod);
            return mem[i][j][x];
        }
    }

    public static class Mathematics {

        public static int ceilPowerOf2(int x) {
            return 32 - Integer.numberOfLeadingZeros(x - 1);
        }

        public static int floorPowerOf2(int x) {
            return 31 - Integer.numberOfLeadingZeros(x);
        }

        public static long modmul(long a, long b, long mod) {
            return b == 0 ? 0 : ((modmul(a, b >> 1, mod) << 1) % mod + a * (b & 1)) % mod;
        }

        /**
         * Get the greatest common divisor of a and b
         */
        public static int gcd(int a, int b) {
            return a >= b ? gcd0(a, b) : gcd0(b, a);
        }

        private static int gcd0(int a, int b) {
            return b == 0 ? a : gcd0(b, a % b);
        }

        public static int extgcd(int a, int b, int[] coe) {
            if (a >= b) {
                return extgcd0(a, b, coe);
            } else {
                int g = extgcd0(b, a, coe);
                int tmp = coe[0];
                coe[0] = coe[1];
                coe[1] = tmp;
                return g;
            }
        }

        private static int extgcd0(int a, int b, int[] coe) {
            if (b == 0) {
                coe[0] = 1;
                coe[1] = 0;
                return a;
            }
            int g = extgcd0(b, a % b, coe);
            int n = coe[0];
            int m = coe[1];
            coe[0] = m;
            coe[1] = n - m * (a / b);
            return g;
        }

        /**
         * Get the greatest common divisor of a and b
         */
        public static long gcd(long a, long b) {
            return a >= b ? gcd0(a, b) : gcd0(b, a);
        }

        private static long gcd0(long a, long b) {
            return b == 0 ? a : gcd0(b, a % b);
        }

        public static long extgcd(long a, long b, long[] coe) {
            if (a >= b) {
                return extgcd0(a, b, coe);
            } else {
                long g = extgcd0(b, a, coe);
                long tmp = coe[0];
                coe[0] = coe[1];
                coe[1] = tmp;
                return g;
            }
        }

        private static long extgcd0(long a, long b, long[] coe) {
            if (b == 0) {
                coe[0] = 1;
                coe[1] = 0;
                return a;
            }
            long g = extgcd0(b, a % b, coe);
            long n = coe[0];
            long m = coe[1];
            coe[0] = m;
            coe[1] = n - m * (a / b);
            return g;
        }

        /**
         * Get y where x * y = 1 (% mod)
         */
        public static int inverse(int x, int mod) {
            return pow(x, mod - 2, mod);
        }

        /**
         * Get x^n(% mod)
         */
        public static int pow(int x, int n, int mod) {
            n = mod(n, mod - 1);
            x = mod(x, mod);
            int bit = 31 - Integer.numberOfLeadingZeros(n);
            long product = 1;
            for (; bit >= 0; bit--) {
                product = product * product % mod;
                if (((1 << bit) & n) != 0) {
                    product = product * x % mod;
                }
            }
            return (int) product;
        }

        public static long longpow(long x, long n, long mod) {
            if (n == 0) {
                return 1;
            }
            long prod = longpow(x, n >> 1, mod);
            prod = modmul(prod, prod, mod);
            if ((n & 1) == 1) {
                prod = modmul(prod, x, mod);
            }
            return prod;
        }

        /**
         * Get x % mod
         */
        public static int mod(int x, int mod) {
            return x >= 0 ? x % mod : (((x % mod) + mod) % mod);
        }

        /**
         * Get n!/(n-m)!
         */
        public static long permute(int n, int m) {
            return m == 0 ? 1 : n * permute(n - 1, m - 1);
        }

        /**
         * Put all primes less or equal to limit into primes after offset
         */
        public static int eulerSieve(int limit, int[] primes, int offset) {
            boolean[] isComp = new boolean[limit + 1];
            int wpos = offset;
            for (int i = 2; i <= limit; i++) {
                if (!isComp[i]) {
                    primes[wpos++] = i;
                }
                for (int j = offset, until = limit / i; j < wpos && primes[j] <= until; j++) {
                    int pi = primes[j] * i;
                    isComp[pi] = true;
                    if (i % primes[j] == 0) {
                        break;
                    }
                }
            }
            return wpos - offset;
        }

        /**
         * Round x into integer
         */
        public static int intRound(double x) {
            if (x < 0) {
                return -(int) (-x + 0.5);
            }
            return (int) (x + 0.5);
        }

        /**
         * Round x into long
         */
        public static long longRound(double x) {
            if (x < 0) {
                return -(long) (-x + 0.5);
            }
            return (long) (x + 0.5);
        }
    }

    public static class FastIO {
        public final StringBuilder cache = new StringBuilder();
        private final InputStream is;
        private final OutputStream os;
        private final Charset charset;
        private StringBuilder defaultStringBuf = new StringBuilder(1 << 8);
        private byte[] buf = new byte[1 << 13];
        private int bufLen;
        private int bufOffset;
        private int next;

        public FastIO(InputStream is, OutputStream os, Charset charset) {
            this.is = is;
            this.os = os;
            this.charset = charset;
        }

        public FastIO(InputStream is, OutputStream os) {
            this(is, os, Charset.forName("ascii"));
        }

        private int read() {
            while (bufLen == bufOffset) {
                bufOffset = 0;
                try {
                    bufLen = is.read(buf);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
                if (bufLen == -1) {
                    return -1;
                }
            }
            return buf[bufOffset++];
        }

        public void skipBlank() {
            while (next >= 0 && next <= 32) {
                next = read();
            }
        }

        public int readInt() {
            int sign = 1;

            skipBlank();
            if (next == '+' || next == '-') {
                sign = next == '+' ? 1 : -1;
                next = read();
            }

            int val = 0;
            if (sign == 1) {
                while (next >= '0' && next <= '9') {
                    val = val * 10 + next - '0';
                    next = read();
                }
            } else {
                while (next >= '0' && next <= '9') {
                    val = val * 10 - next + '0';
                    next = read();
                }
            }

            return val;
        }

        public long readLong() {
            int sign = 1;

            skipBlank();
            if (next == '+' || next == '-') {
                sign = next == '+' ? 1 : -1;
                next = read();
            }

            long val = 0;
            if (sign == 1) {
                while (next >= '0' && next <= '9') {
                    val = val * 10 + next - '0';
                    next = read();
                }
            } else {
                while (next >= '0' && next <= '9') {
                    val = val * 10 - next + '0';
                    next = read();
                }
            }

            return val;
        }

        public double readDouble() {
            boolean sign = true;
            skipBlank();
            if (next == '+' || next == '-') {
                sign = next == '+';
                next = read();
            }

            long val = 0;
            while (next >= '0' && next <= '9') {
                val = val * 10 + next - '0';
                next = read();
            }
            if (next != '.') {
                return sign ? val : -val;
            }
            next = read();
            long radix = 1;
            long point = 0;
            while (next >= '0' && next <= '9') {
                point = point * 10 + next - '0';
                radix = radix * 10;
                next = read();
            }
            double result = val + (double) point / radix;
            return sign ? result : -result;
        }

        public String readString(StringBuilder builder) {
            skipBlank();

            while (next > 32) {
                builder.append((char) next);
                next = read();
            }

            return builder.toString();
        }

        public String readString() {
            defaultStringBuf.setLength(0);
            return readString(defaultStringBuf);
        }

        public int readLine(char[] data, int offset) {
            int originalOffset = offset;
            while (next != -1 && next != '\n') {
                data[offset++] = (char) next;
                next = read();
            }
            return offset - originalOffset;
        }

        public int readString(char[] data, int offset) {
            skipBlank();

            int originalOffset = offset;
            while (next > 32) {
                data[offset++] = (char) next;
                next = read();
            }

            return offset - originalOffset;
        }

        public int readString(byte[] data, int offset) {
            skipBlank();

            int originalOffset = offset;
            while (next > 32) {
                data[offset++] = (byte) next;
                next = read();
            }

            return offset - originalOffset;
        }

        public char readChar() {
            skipBlank();
            char c = (char) next;
            next = read();
            return c;
        }

        public void flush() {
            try {
                os.write(cache.toString().getBytes(charset));
                os.flush();
                cache.setLength(0);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        public boolean hasMore() {
            skipBlank();
            return next != -1;
        }
    }

    public static class Debug {
        private boolean allowDebug;

        public Debug(boolean allowDebug) {
            this.allowDebug = allowDebug;
        }

        public void assertTrue(boolean flag) {
            if (!allowDebug) {
                return;
            }
            if (!flag) {
                fail();
            }
        }

        public void fail() {
            throw new RuntimeException();
        }

        public void assertFalse(boolean flag) {
            if (!allowDebug) {
                return;
            }
            if (flag) {
                fail();
            }
        }

        private void outputName(String name) {
            System.out.print(name + " = ");
        }

        public void debug(String name, int x) {
            if (!allowDebug) {
                return;
            }

            outputName(name);
            System.out.println("" + x);
        }

        public void debug(String name, long x) {
            if (!allowDebug) {
                return;
            }
            outputName(name);
            System.out.println("" + x);
        }

        public void debug(String name, double x) {
            if (!allowDebug) {
                return;
            }
            outputName(name);
            System.out.println("" + x);
        }

        public void debug(String name, int[] x) {
            if (!allowDebug) {
                return;
            }
            outputName(name);
            System.out.println(Arrays.toString(x));
        }

        public void debug(String name, long[] x) {
            if (!allowDebug) {
                return;
            }
            outputName(name);
            System.out.println(Arrays.toString(x));
        }

        public void debug(String name, double[] x) {
            if (!allowDebug) {
                return;
            }
            outputName(name);
            System.out.println(Arrays.toString(x));
        }

        public void debug(String name, Object x) {
            if (!allowDebug) {
                return;
            }
            outputName(name);
            System.out.println("" + x);
        }

        public void debug(String name, Object... x) {
            if (!allowDebug) {
                return;
            }
            outputName(name);
            System.out.println(Arrays.deepToString(x));
        }
    }
}


//package Contest551;

import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

public class mainF {
    public static Scanner enter = new Scanner(System.in);
    public static PrintWriter out = new PrintWriter(System.out);
    public static long mod=998244353;
    public static long cnk[][]=new long[(int)2e3+1][(int)2e3+1];
    public static long fact[]=new long[2*(int)2e3+1];
    public static long reverse[]=new long[2*(int)2e3+1];
    public static long deg_2[]=new long[(int)2e3+1];
    public static void main(String[] args) {
        long t=System.currentTimeMillis();
        cnk[0][0]=1;
        for (int i = 1; i <cnk.length ; i++) {
            cnk[0][i]=1;
            for (int j = 1; j <=i ; j++) {
                cnk[j][i]=cnk[j-1][i-1]+cnk[j][i-1];
                cnk[j][i]%=mod;
            }
        }
        fact[0]=1;
        deg_2[0]=1;
        for (int i = 1; i <fact.length ; i++) {
            fact[i]=fact[i-1]*i;
            fact[i]%=mod;
        }
        for (int i = 1; i <deg_2.length ; i++) {
            deg_2[i]=deg_2[i-1]*2;
            deg_2[i]%=mod;
        }
        reverse[1]=1;
        for (int i = 3; i <reverse.length ; i+=2) {
            reverse[i]=bin_pow(fact[i],mod-2,mod);
        }
       /* System.out.println(Arrays.toString(reverse));
        System.out.println(fact[5]);
        System.out.println(reverse[5]);*/
        int n=enter.nextInt();
        int k=enter.nextInt();
        int l=enter.nextInt();
        long ans=0;
        for (int i = k; i <=n ; i++) {
            long tmp=0;
            for (int s = 0,c=1; s <=n-i ; s++,c*=-1) {
                tmp+=cnk[s][n-i]*deg_2[s]*fact[s+i]*fact[s+i]*reverse[2*(s+i)+1]*c;
                tmp%=mod;
               // System.out.println(reverse[2*(s+i)+1]);
            }
            //System.out.println(tmp);
            ans+=cnk[i][n]*deg_2[i]*tmp;
            ans%=mod;
        }
        ans*=l;
        ans%=mod;
        System.out.println(ans);

      //  System.out.println(System.currentTimeMillis()-t);

    }
    public static long bin_pow(long a,long b, long mod){//a^b %mod
        long ans=1;
        while(b!=0){
            if((b&1)==1) ans*=a;
            a*=a;
            ans%=mod;
            a%=mod;
            b>>=1;
        }
        return ans;
    }
}


//package Contest551;

import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

public class mainF {
    public static Scanner enter = new Scanner(System.in);
    public static PrintWriter out = new PrintWriter(System.out);
    public static long mod=998244353;
    public static long cnk[][]=new long[(int)2e3+1][(int)2e3+1];
    public static long fact[]=new long[2*(int)2e3+1];
    public static long reverse[]=new long[2*(int)2e3+1];
    public static long deg_2[]=new long[(int)2e3+1];
    public static void main(String[] args) {
        long t=System.currentTimeMillis();
        cnk[0][0]=1;
        for (int i = 1; i <cnk.length ; i++) {
            cnk[0][i]=1;
            for (int j = 1; j <=i ; j++) {
                cnk[j][i]=cnk[j-1][i-1]+cnk[j][i-1];
                cnk[j][i]%=mod;
            }
        }
        fact[0]=1;
        deg_2[0]=1;
        for (int i = 1; i <fact.length ; i++) {
            fact[i]=fact[i-1]*i;
            fact[i]%=mod;
        }
        for (int i = 1; i <deg_2.length ; i++) {
            deg_2[i]=deg_2[i-1]*2;
            deg_2[i]%=mod;
        }
        reverse[1]=1;
        for (int i = 3; i <reverse.length ; i+=2) {
            reverse[i]=bin_pow(fact[i],mod-2,mod);
        }
       /* System.out.println(Arrays.toString(reverse));
        System.out.println(fact[5]);
        System.out.println(reverse[5]);*/
        int n=enter.nextInt();
        int k=enter.nextInt();
        long l=enter.nextInt();
        l%=mod;
        long ans=0;
        for (int i = k; i <=n ; i++) {
            long tmp=0;
            for (int s = 0,c=1; s <=n-i ; s++,c*=-1) {
                long a=1;
                a*=cnk[s][n-i]*deg_2[s];
                a%=mod;
                a*=fact[s+i];
                a%=mod;
                a*=fact[s+i];
                a%=mod;
                a*=reverse[2*(s+i)+1];
                a%=mod;
                tmp+=a*c;
                tmp%=mod;
               // System.out.println(reverse[2*(s+i)+1]);
            }
            //System.out.println(tmp);
            /*ans+=cnk[i][n]*deg_2[i]*tmp;
            ans%=mod;*/
            long  b=1;
            b*=tmp*deg_2[i];
            b%=mod;
            //System.out.println(b);
            b*=cnk[i][n];
            b%=mod;
            ans+=b;
            ans%=mod;
        }
        ans*=l;
        ans%=mod;
        System.out.println((ans<0)? (ans+mod) : ans);

      //  System.out.println(System.currentTimeMillis()-t);

    }
    public static long bin_pow(long a,long b, long mod){//a^b %mod
        long ans=1;
        while(b!=0){
            if((b&1)==1) ans*=a;
            a*=a;
            ans%=mod;
            a%=mod;
            b>>=1;
        }
        return ans;
    }
}


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

public class E890 {

	long mod = 1000000000L+7L;
	long[] fac;
	long[] f;

	private void solve() throws Exception {
		int n = nextInt();
		int k = nextInt();
		fac = new long[n+1];
		fac[0] = 1;
		for(int i = 1; i <= n; i++) fac[i] = (fac[i-1]*i)%mod;
		f = new long[n+1];
		for(int i = 0; i <= Math.min(k,n); i++) f[i] = fac[i];
		for(int i = k; i < n; i++) f[i+1] = (((i+1)*f[i])%mod - ((fac[i] * f[i-k])%mod * inverse(fac[i-k]))%mod + mod)%mod;
		long res = 0;
		for(int i = 0; i < n; i++) res = (res+(f[n-i-1]*(fac[n-1]*inverse(fac[n-1-i]))%mod)%mod)%mod;
		out.println((fac[n]-res+mod)%mod);
	}

	long inverse(long n) {
        long i = mod, v = 0, d = 1;
        while (n>0) {
            long t = i/n, x = n;
            n = i % x;
            i = x;
            x = d;
            d = v - t*x;
            v = x;
        }
        v %= mod;
        return (v+mod)%mod;
    }

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

	private BufferedReader in;
	private PrintWriter out;
	private StringTokenizer tokenizer;

	public void run() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			tokenizer = null;
			out = new PrintWriter(System.out);
			solve();
			in.close();
			out.close();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

	private int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	private long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	private float nextFloat() throws IOException {
		return Float.parseFloat(nextToken());
	}

	private String nextLine() throws IOException {
		return new String(in.readLine());
	}

	private String nextToken() throws IOException {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			tokenizer = new StringTokenizer(in.readLine());
		}
		return tokenizer.nextToken();
	}

}


import java.util.*;
public class HelloWorld{

     public static void main(String []args){
        Scanner sc=new Scanner(System.in);
        int a=sc.nextInt(),b=sc.nextInt(),c=sc.nextInt(),int cnt=0;
        if((a+b)>c && (b+c)>a && (a+c)>b )
        {
            System.out.println("0");
            return;
        }
        else{
            if((a+b)<=c)
            cnt+=(c-(a+b)+1);
            if((c+b)<=a)
             cnt+=(a-(c+b)+1);
            if((a+c)<=b)
             cnt+=(b-(a+c)+1);
            System.out.println(cnt);
        }
     }
}


public class GFG {
	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();

        int[] p = new int[3];
        p[0] = a;
        p[1] = b;
        p[2] = c;
        Arrays.sort(p);

        if((p[0] + p[1] > p[2]) && (p[0] + p[2] > p[1]) && (p[1] + p[2] > p[0])){
            System.out.println("0");
        }
        else{
            if((p[0] + p[1] <= p[2])){
                System.out.println(p[2] - (p[0] +  p[1]) + 1);
            }
            if((p[0] + p[2] <= p[1])){
                System.out.println(p[1] - (p[0] +  p[2]) + 1);
            }
            if((p[1] + p[2] <= p[0])){
                System.out.println(p[0] - (p[1] +  p[2]) + 1);
            }
        }

   }
}


import java.io.*;
import java.util.*;
import java.math.*;

public class Main {

    public static void main(String[] args) throws java.lang.Exception {
        Reader pm =new Reader();
        //Scanner pm = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int n = pm.nextInt();
        int[] a = new int[n];
        for(int i=0;i<n;i++)
            a[i] = pm.nextInt();
        StringBuffer sb = new StringBuffer();
        HashSet<Integer> book = new HashSet<>();
        for(int i=0;i<n;i++){
            char c = (char)(i+97);
            while(book.contains(a[i]) && a[i] >=0){
                a[i]--;
            }
            book.add(a[i]);
            while(a[i]-- > 0)
                sb.append(c);

        }
        //System.out.println(sb);
        System.out.println(sb.length());
    }

    static class Reader {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

        public Reader()
        {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public Reader(String file_name) throws IOException
        {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public String readLine() throws IOException
        {
            byte[] buf = new byte[64]; // line length
            int cnt = 0, c;
            while ((c = read()) != -1)
            {
                if (c == '\n')
                    break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }

        public int nextInt() throws IOException
        {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do
            {
                ret = ret * 10 + c - '0';
            }  while ((c = read()) >= '0' && c <= '9');

            if (neg)
                return -ret;
            return ret;
        }

        public long nextLong() throws IOException
        {
            long ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public double nextDouble() throws IOException
        {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();

            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');

            if (c == '.')
            {
                while ((c = read()) >= '0' && c <= '9')
                {
                    ret += (c - '0') / (div *= 10);
                }
            }

            if (neg)
                return -ret;
            return ret;
        }

        private void fillBuffer() throws IOException
        {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }

        private byte read() throws IOException
        {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }

        public void close() throws IOException
        {
            if (din == null)
                return;
            din.close();
        }
    }
}


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

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class CF327A {
    static BufferedReader __in;
    static PrintWriter __out;
    static StringTokenizer input;

    public static void main(String[] args) throws IOException {
        __in = new BufferedReader(new InputStreamReader(System.in));
        __out = new PrintWriter(new OutputStreamWriter(System.out));

        int n = ri();
        int[] a = ria(n);
        int cnt_1 = 0, flip_0 = 0, flip_max = -1;
        for(int i = 0; i < n; ++i) {
            if(a[i] == 1) {
                ++cnt_1;
                flip_0 = 0;
            }
            else {
                ++flip_0;
                flip_max = max(flip_max, flip_0);
            }
        }
        prln(cnt_1 + flip_max);

        close();
    }

    // references
    // IBIG = 1e9 + 7
    // IRAND ~= 3e8
    // IMAX ~= 2e10
    // LMAX ~= 9e18
    // constants
    static final int IBIG = 1000000007;
    static final int IRAND = 327859546;
    static final int IMAX = 2147483647;
    static final int IMIN = -2147483648;
    static final long LMAX = 9223372036854775807L;
    static final long LMIN = -9223372036854775808L;
    // util
    static int minof(int a, int b, int c) {return min(a, min(b, c));}
    static int minof(int... x) {return x.length == 1 ? x[0] : x.length == 2 ? min(x[0], x[1]) : min(x[0], minstarting(1, x));}
    static int minstarting(int offset, int... x) {assert x.length > 2; return offset == x.length - 2 ? min(x[offset], x[offset + 1]) : min(x[offset], minstarting(offset + 1, x));}
    static long minof(long a, long b, long c) {return min(a, min(b, c));}
    static long minof(long... x) {return x.length == 1 ? x[0] : x.length == 2 ? min(x[0], x[1]) : min(x[0], minstarting(1, x));}
    static long minstarting(int offset, long... x) {assert x.length > 2; return offset == x.length - 2 ? min(x[offset], x[offset + 1]) : min(x[offset], minstarting(offset + 1, x));}
    static int maxof(int a, int b, int c) {return max(a, max(b, c));}
    static int maxof(int... x) {return x.length == 1 ? x[0] : x.length == 2 ? max(x[0], x[1]) : max(x[0], maxstarting(1, x));}
    static int maxstarting(int offset, int... x) {assert x.length > 2; return offset == x.length - 2 ? max(x[offset], x[offset + 1]) : max(x[offset], maxstarting(offset + 1, x));}
    static long maxof(long a, long b, long c) {return max(a, max(b, c));}
    static long maxof(long... x) {return x.length == 1 ? x[0] : x.length == 2 ? max(x[0], x[1]) : max(x[0], maxstarting(1, x));}
    static long maxstarting(int offset, long... x) {assert x.length > 2; return offset == x.length - 2 ? max(x[offset], x[offset + 1]) : max(x[offset], maxstarting(offset + 1, x));}
    static int powi(int a, int b) {if(a == 0) return 0; int ans = 1; while(b > 0) {if((b & 1) > 0) ans *= a; a *= a; b >>= 1;} return ans;}
    static long powl(long a, int b) {if(a == 0) return 0; long ans = 1; while(b > 0) {if((b & 1) > 0) ans *= a; a *= a; b >>= 1;} return ans;}
    static int floori(double d) {return (int)d;}
    static int ceili(double d) {return (int)ceil(d);}
    static long floorl(double d) {return (long)d;}
    static long ceill(double d) {return (long)ceil(d);}
    // input
    static void r() throws IOException {input = new StringTokenizer(__in.readLine());}
    static int ri() throws IOException {return Integer.parseInt(__in.readLine());}
    static long rl() throws IOException {return Long.parseLong(__in.readLine());}
    static int[] ria(int n) throws IOException {int[] a = new int[n]; input = new StringTokenizer(__in.readLine()); for(int i = 0; i < n; ++i) a[i] = Integer.parseInt(input.nextToken()); return a;}
    static long[] rla(int n) throws IOException {long[] a = new long[n]; input = new StringTokenizer(__in.readLine()); for(int i = 0; i < n; ++i) a[i] = Long.parseLong(input.nextToken()); return a;}
    static char[] rcha() throws IOException {return __in.readLine().toCharArray();}
    static String rline() throws IOException {return __in.readLine();}
    static int rni() throws IOException {input = new StringTokenizer(__in.readLine()); return Integer.parseInt(input.nextToken());}
    static int ni() {return Integer.parseInt(input.nextToken());}
    static long rnl() throws IOException {input = new StringTokenizer(__in.readLine()); return Long.parseLong(input.nextToken());}
    static long nl() {return Long.parseLong(input.nextToken());}
    // output
    static void pr(int i) {__out.print(i);}
    static void prln(int i) {__out.println(i);}
    static void pr(long l) {__out.print(l);}
    static void prln(long l) {__out.println(l);}
    static void pr(double d) {__out.print(d);}
    static void prln(double d) {__out.println(d);}
    static void pr(char c) {__out.print(c);}
    static void prln(char c) {__out.println(c);}
    static void pr(char[] s) {__out.print(new String(s));}
    static void prln(char[] s) {__out.println(new String(s));}
    static void pr(String s) {__out.print(s);}
    static void prln(String s) {__out.println(s);}
    static void pr(Object o) {__out.print(o);}
    static void prln(Object o) {__out.println(o);}
    static void prln() {__out.println();}
    static void pryes() {__out.println("yes");}
    static void pry() {__out.println("Yes");}
    static void prY() {__out.println("YES");}
    static void prno() {__out.println("no");}
    static void prn() {__out.println("No");}
    static void prN() {__out.println("NO");}
    static void pryesno(boolean b) {__out.println(b ? "yes" : "no");}
    static void pryn(boolean b) {__out.println(b ? "Yes" : "No");}
    static void prYN(boolean b) {__out.println(b ? "YES" : "NO");}
    static void prln(int... a) {for(int i = 0, len = a.length - 1; i < len; __out.print(a[i]), __out.print(' '), ++i); __out.println(a[a.length - 1]);}
    static void prln(long... a) {for(int i = 0, len = a.length - 1; i < len; __out.print(a[i]), __out.print(' '), ++i); __out.println(a[a.length - 1]);}
    static <T> void prln(Collection<T> c) {int n = c.size() - 1; Iterator<T> iter = c.iterator(); for(int i = 0; i < n; __out.print(iter.next()), __out.print(' '), ++i); __out.println(iter.next());}
    static void flush() {__out.flush();}
    static void close() {__out.close();}}


import java.util.Scanner; // this is a way we use to get an input from the user .. we import a scanner that is already built in java .. and we write it before our class.
public class main {

    public static void main(String args[]){ //method header

        //System.out.println("hello world !!"); //method type ... the both create the method we need .

        Scanner haha=new Scanner(System.in);
        int h, g;
        h=haha.nextInt();
        g=haha.nextInt();
        int a=0 , b=0;
        if(h>g){

            b=(h-g)/2;
            a=g;}
        else{
            b=(g-h)/2;
            a=h;}
        System.out.print(a);
        System.out.print(" ");
        System.out.print(b);


import java.io.*;
//import java.util.*;

public class A581 {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    PrintWriter out = new PrintWriter(System.out);
    int a = in.nextInt();
    int b = in.nextInt();
    int c;
    if (a < b) {
      out.println(a+" "+((b-a)/2));
    } else {
      out.println(b+" "+((a-b)/2));
    }
    out.close();
  }
}


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import java.util.Scanner;

/**
 *
 * @author tino
 */
public class SpecialTask {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        String x = input.next();
        boolean bol[] = new boolean[10];
        int s;
        int total = 1;
        if ( x.charAt(0)-48< 10 )
            s = 10;
        else
            s = 9;

        for (int i = 0; i < x.length(); i++) {
            int value = x.charAt(i);
            if (i == 0 && s == 9) {
                total = total * 9;
                bol[value-65] = true;
            } else {
                if (65 <= value && 75 >= value && bol[value-65] == false) {
                    bol[value - 65] = true;
                    total = total * s;
                    s--;
                }
                else if (value == '?' && i>0) {
                    total = total * 10;
                }
                else if(value == '?' && i==0)
                    total= total*9;
            }
        }
        System.out.println(total);

    }
    }


import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.SortedSet;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

/**
 * #
 *
 * @author pttrung
 */
public class D_Round_51 {

	public static long MOD = 1000000007;

	public static void main(String[] args) throws FileNotFoundException {
		// PrintWriter out = new PrintWriter(new FileOutputStream(new File(
		// "output.txt")));
		PrintWriter out = new PrintWriter(System.out);
		Scanner in = new Scanner();
		int t = in.nextInt();
		long[][][][][] dp = new long[2][2][2][2521][(1 << 10)];
		int[][][][] check = new int[2][2][2521][(1<<10)];
		int cached = 0;
		for (int z = 0; z < t; z++) {
			long l = in.nextLong();
			long r = in.nextLong();
			long result = 0;
			for (int i = 0; i < (1 << 10); i++) {
				int lcm = 1;
				for (int j = 1; j < 10; j++) {
					if (((1 << j) & i) != 0) {
						lcm = (int) (lcm * j / gcd(lcm, j));
					}
				}
				//System.out.println(lcm);

				dp[0][0][0][0][0] = 1;
				LinkedList<State> q = new LinkedList();
				q.add(new State(0, 0, 0, 0));

				int cur = 1;
				for (int j = 19; j >= 0; j--) {
					cached++;
					LinkedList<State> nxt = new LinkedList();

					int a = get(j, l);
					int b = get(j, r);
					while (!q.isEmpty()) {
						State s = q.poll();
						for (int k = 0; k < 10; k++) {
							if (((1 << k) & i) != 0) {
								if (k >= a || s.l == 1) {
									if (k <= b || s.s == 1) {
										int tmp = (s.mod*10 + k)  % lcm;
										int y = k > a ? 1 : s.l;
										int x = k < b ? 1 : s.s;
										int u = (1 << k) | s.u;
										if (check[x][y][tmp][u] != cached) {
											check[x][y][tmp][u] = cached;
											dp[cur][x][y][tmp][u] = 0;
											nxt.add(new State(x, y, tmp, u));
										}
										dp[cur][x][y][tmp][u] += dp[1 - cur][s.s][s.l][s.mod][s.u];
									}
								}
							}
						}
					}
					q = nxt;
					if (j == 0) {
						for (State v : q) {
							if (v.mod == 0 && v.u == i) {
								result += dp[cur][v.s][v.l][v.mod][v.u];
							}
						}
					}
					cur = 1 - cur;
				}
			}
			out.println(result);
		}
		out.close();
	}

	static class State {
		int s, l, mod, u;

		public State(int s, int l, int mod, int u) {
			super();
			this.s = s;
			this.l = l;
			this.mod = mod;
			this.u = u;
		}

	}

	public static int get(int digit, long v) {
		for (int i = 0; i < digit; i++) {
			v /= 10;
		}
		return (int) v % 10;
	}

	public static int[] KMP(String val) {
		int i = 0;
		int j = -1;
		int[] result = new int[val.length() + 1];
		result[0] = -1;
		while (i < val.length()) {
			while (j >= 0 && val.charAt(j) != val.charAt(i)) {
				j = result[j];
			}
			j++;
			i++;
			result[i] = j;
		}
		return result;

	}

	public static boolean nextPer(int[] data) {
		int i = data.length - 1;
		while (i > 0 && data[i] < data[i - 1]) {
			i--;
		}
		if (i == 0) {
			return false;
		}
		int j = data.length - 1;
		while (data[j] < data[i - 1]) {
			j--;
		}
		int temp = data[i - 1];
		data[i - 1] = data[j];
		data[j] = temp;
		Arrays.sort(data, i, data.length);
		return true;
	}

	public static int digit(long n) {
		int result = 0;
		while (n > 0) {
			n /= 10;
			result++;
		}
		return result;
	}

	public static double dist(long a, long b, long x, long y) {
		double val = (b - a) * (b - a) + (x - y) * (x - y);
		val = Math.sqrt(val);
		double other = x * x + a * a;
		other = Math.sqrt(other);
		return val + other;

	}

	public static class Point implements Comparable<Point> {

		int x, y;

		public Point(int start, int end) {
			this.x = start;
			this.y = end;
		}

		@Override
		public int hashCode() {
			int hash = 5;
			hash = 47 * hash + this.x;
			hash = 47 * hash + this.y;
			return hash;
		}

		@Override
		public boolean equals(Object obj) {
			if (obj == null) {
				return false;
			}
			if (getClass() != obj.getClass()) {
				return false;
			}
			final Point other = (Point) obj;
			if (this.x != other.x) {
				return false;
			}
			if (this.y != other.y) {
				return false;
			}
			return true;
		}

		@Override
		public int compareTo(Point o) {
			return x - o.x;
		}
	}

	public static class FT {

		long[] data;

		FT(int n) {
			data = new long[n];
		}

		public void update(int index, long value) {
			while (index < data.length) {
				data[index] += value;
				index += (index & (-index));
			}
		}

		public long get(int index) {
			long result = 0;
			while (index > 0) {
				result += data[index];
				index -= (index & (-index));
			}
			return result;

		}
	}

	public static long gcd(long a, long b) {
		if (b == 0) {
			return a;
		}
		return gcd(b, a % b);
	}

	public static long pow(long a, long b) {
		if (b == 0) {
			return 1;
		}
		if (b == 1) {
			return a;
		}
		long val = pow(a, b / 2);
		if (b % 2 == 0) {
			return val * val % MOD;
		} else {
			return val * (val * a % MOD) % MOD;

		}
	}

	static class Scanner {

		BufferedReader br;
		StringTokenizer st;

		public Scanner() throws FileNotFoundException {
			// System.setOut(new PrintStream(new
			// BufferedOutputStream(System.out), true));
			br = new BufferedReader(new InputStreamReader(System.in));
			// br = new BufferedReader(new InputStreamReader(new
			// FileInputStream(new File("input.txt"))));
		}

		public String next() {

			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (Exception e) {
					throw new RuntimeException();
				}
			}
			return st.nextToken();
		}

		public long nextLong() {
			return Long.parseLong(next());
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}

		public String nextLine() {
			st = null;
			try {
				return br.readLine();
			} catch (Exception e) {
				throw new RuntimeException();
			}
		}

		public boolean endLine() {
			try {
				String next = br.readLine();
				while (next != null && next.trim().isEmpty()) {
					next = br.readLine();
				}
				if (next == null) {
					return true;
				}
				st = new StringTokenizer(next);
				return st.hasMoreTokens();
			} catch (Exception e) {
				throw new RuntimeException();
			}
		}
	}
}


import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Random;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

//  WeekOfCode21

public class Solution {
	public static InputReader in;
	public static PrintWriter out;
	public static Random ra = new Random(0);

	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		in = new InputReader(inputStream);
//		out = new PrintWriter(outputStream, true);
		out = new PrintWriter(outputStream, false); // enable this for ludicrous speed

		beautifulNumbers();
//		testBM();
//		borrowingMoney();
//		lazySorting();
//		testLazySorting();
//		luckBalance();
//		kangaroo();

		out.close();
	}

	static void beautifulNumbers() {
		int cnt = 0;
		for(int i=1; i<=MOD; i++)
			if(MOD%i == 0)
				Hash[i] = cnt++;

		for(int i=0; i < dp.length; i++) {
			for(int j=0; j < dp[0].length; j++) {
				Arrays.fill(dp[i][j], -1);
			}
		}

		int ts = in.nextInt();
		for (int t = 0; t < ts; t++) {
			long a = in.nextInt();
			long b = in.nextInt();
			System.out.println((solve(b) - solve(a-1)));
		}
	}

	static final int MOD = 2520;
	static long[][][] dp = new long[20][50][2550];
	static int[] dis = new int[20];
	static int[] Hash = new int[2550];

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

	static long dfs(int len, int num, int lcm, boolean flag) {
		if(-1==len) return (num%lcm == 0) ? 1: 0;
		if(!flag && -1!=dp[len][Hash[lcm]][num]) {
			return dp[len][Hash[lcm]][num];
		}
		long ans = 0;
		int end = flag?dis[len]:9;
		for(int i=0; i<=end; i++)
			ans += dfs(len-1, (num*10+i)%MOD, (int)(i > 0 ? lcm*i/gcd(lcm,i) : lcm), flag && i==end);
		if(!flag) dp[len][Hash[lcm]][num] = ans;
		return ans;
	}

	static long solve(long n) {
		int pos = 0;
		while(n > 0) {
			dis[pos++] = (int)n%10;
			n /= 10;
		}
		return dfs(pos-1, 0, 1, true);
	}

	public static void testBM() {
		long t1 = System.currentTimeMillis();
		for (int test = 0; test < 1000000; test++) {
			int N = ra.nextInt(10)+1;
			int M = ra.nextInt(N*(N-1)/2 +1);
			boolean[][] g = new boolean[N][N];
			int[] cost = new int[N];
			for (int i = 0; i < cost.length; i++) {
				cost[i] = ra.nextInt(100);
			}
			for (int i = 0; i < M && N > 1; i++) {
				int a = ra.nextInt(N);
				int b = ra.nextInt(N);
				while (a == b) {
					a = ra.nextInt(N);
					b = ra.nextInt(N);
				}
				g[a][b] = true;
				g[b][a] = true;
			}
			String r1 = borrowingMoneySlow(N, g, cost);
			String r2 = borrowingMoney(N, g, cost);
			if (!r1.equals(r2)) {
				System.out.println("fail");
				borrowingMoneySlow(N, g, cost);
				borrowingMoney(N, g, cost);
			}
		}
		System.out.println(System.currentTimeMillis() - t1);
	}

	public static void borrowingMoney() {
		int N = 0;
		boolean[][] g;
		int[] cost;

		N = in.nextInt();
		int m = in.nextInt();
		cost = in.nextIntArray(N);
		g = new boolean[N][N];

		for (int i = 0; i < m; i++) {
			int a = in.nextInt()-1;
			int b = in.nextInt()-1;
			g[a][b] = true;
			g[b][a] = true;
		}

		System.out.println(borrowingMoney(N, g, cost));
//		System.out.println(borrowingMoneySlow(N, g, cost));

	}

	public static String borrowingMoneySlow(int ns, boolean[][] g, int[] cost) {
		int len = ns;
		int N = 1 << len;
		int[] costF = new int[100*35 +1];
		for (int n = 0; n < N; n++) {
			boolean[] active = new boolean[len];
			for (int i = 0; i < len; i++) {
				if (((1 << i) & n) != 0) {
					active[i] = true;
				}
			}
			int sum = 0;
			boolean v = true;
			for (int i = 0; i < ns; i++) {
				if (!active[i]) {
					for (int j = 0; j < ns; j++) {
						if (g[i][j] && !active[j]) {
							v = false;
							break;
						}
					}
					sum += cost[i];
				}
				if (!v) {
					if (i >= 1) {
						System.currentTimeMillis();
					}
					break;
				}
			}
			if (v) {
				costF[sum]++;
			}
		}
		for (int i = costF.length-1; i >= 0; i--) {
			if (costF[i] > 0) {
				return i + " " + costF[i];
			}
		}
		return "";
	}

	public static String borrowingMoney(int N, boolean[][] g, int[] cost) {
		boolean[] visit;
		visit = new boolean[N];
		HashMap<Long, Long> F;
		F = new HashMap<>();

		long mx = 0;
		long tw = 1;
		for (int p = 0; p < visit.length; p++) {
			if (!visit[p]) {
				F = new HashMap<>();

				Queue<Integer> q = new LinkedList<>();
				q.add(p);
				boolean start = true;

				while (!q.isEmpty()) {
					int top = q.poll();

					if (!visit[top]) {
						visit[top] = true;
						HashMap<Long, Long> current = F;
						HashMap<Long, Long> oldF = new HashMap<>();
						for (Entry<Long, Long> e: current.entrySet()) {
							oldF.put(e.getKey(), e.getValue());
						}
						if (start) {
							start = false;

							// do nothing
							current.put(0L, 0L);

							// steal here
							current.put(1L << top, (long)cost[top]);
						} else {
							// steal here

							for (Entry<Long, Long> e: oldF.entrySet()) {
								if (!getBit(e.getKey(), top)) {
									boolean stillHere = true;
									for (int i = 0; i < N; i++) {
										// top will have left if someone robbed next door
										if (g[top][i] && getBit(e.getKey(), i)) {
											stillHere = false;
										}
									}
									if (stillHere) {
										long max = e.getValue();
										long fmask = e.getKey() | 1L << top;

										if (max > -1) {
											max += cost[top];
											if (!current.containsKey(fmask) || current.get(fmask) < max) {
												current.put(fmask, max);
											}
										}
									}
								}
							}
						}

						for (int i = 0; i < N; i++) {
							if (g[top][i]) {
								q.add(i);
							}
						}

						// If all of a edge's neighbours have been visited, it's removed from the searchable set
						// and the maximum of all of them are added back because they cannot influence future
						// events.

						for (Entry<Long, Long> e: oldF.entrySet()) {
							if (!getBit(e.getKey(), top)) {
								boolean stillHere = true;
								for (int i = 0; i < N; i++) {
									// top will have left if someone robbed next door
									if (g[top][i] && getBit(e.getKey(), i)) {
										stillHere = false;
									}
								}
								if (stillHere) {
									long max = e.getValue();
									long fmask = e.getKey() | 1L << top;

									if (max > -1) {
										max += cost[top];
										if (!current.containsKey(fmask) || current.get(fmask) < max) {
											current.put(fmask, max);
										}
									}
								}
							}
						}

					}
				}

				long max = -1;
				for (Entry<Long, Long> e: F.entrySet()) {
					if (e.getValue() > max) {
						max = e.getValue();
					}
				}
				long ways = 0;
				for (Entry<Long, Long> e: F.entrySet()) {
					if (e.getValue() == max) {
						ways++;
					}
				}
				mx += max;
				tw *= ways;
			}
		}

		//System.out.println(max + " " + ways + " " + Long.toBinaryString(fmask));

		return (mx + " " + tw);
	}

	public static String borrowingMoney2(int N, boolean[][] g, int[] cost) {
		boolean[] visit;
		visit = new boolean[N];
		HashMap<Long, Long> F;
		F = new HashMap<>();

		long mx = 0;
		long tw = 1;
		for (int i = 0; i < visit.length; i++) {
			if (!visit[i]) {
				F = new HashMap<>();

				dfs(true, i, N, g, visit, cost, F);

				long max = -1;
				long fmask = 0;
				for (Entry<Long, Long> e: F.entrySet()) {
					if (e.getValue() > max) {
						max = e.getValue();
						fmask = e.getKey();
					}
				}
				long ways = 0;
				for (Entry<Long, Long> e: F.entrySet()) {
					if (e.getValue() == max) {
						ways++;
					}
				}
				mx += max;
				tw *= ways;
			}
		}

		//System.out.println(max + " " + ways + " " + Long.toBinaryString(fmask));

		return (mx + " " + tw);
	}

	public static void dfs(boolean start, int top, int N, boolean[][] g, boolean[] visit, int[] cost, HashMap<Long, Long> F) {
		if (!visit[top]) {
			visit[top] = true;
			HashMap<Long, Long> current = F;
			HashMap<Long, Long> oldF = new HashMap<>();
			for (Entry<Long, Long> e: current.entrySet()) {
				oldF.put(e.getKey(), e.getValue());
			}
			if (start) {

				// do nothing
				current.put(0L, 0L);

				// steal here
				long fmask = 0;
				for (int i = 0; i < N; i++) {
					if (g[top][i]) {
						fmask |= 1L << i;
					}
				}
				current.put(fmask, (long)cost[top]);
			} else {
				// steal here

				for (Entry<Long, Long> e: oldF.entrySet()) {
					if (!getBit(e.getKey(), top)) {
						long max = e.getValue();
						long fmask = e.getKey();

						for (int i = 0; i < N; i++) {
							if (g[top][i]) {
								fmask |= 1L << i;
							}
						}
						if (max > -1) {
							max += cost[top];
							if (!current.containsKey(fmask) || current.get(fmask) < max) {
								current.put(fmask, max);
							}
//							if (current.get(fmask) == max) {
//								current.put(fmask, max);
//							}
						}
					}
				}
			}

			for (int i = 0; i < N; i++) {
				if (g[top][i]) {
					dfs(false, i, N, g, visit, cost, F);
				}
			}
		}
	}

	public static int clearBit(int x, int i) {
		return (x & ~(1 << i));
	}

	public static int setBit(int x, int i) {
		return (x | (1 << i));
	}

	public static boolean getBit(long x, int i) {
		return (x & (1L << i)) != 0;
	}

	public static void testLazySorting() {
		int[] a = new int[4];
		for (int i = 0; i < 10; i++) {
			for (int j = 0; j < a.length; j++) {
				a[j] = ra.nextInt(10);
			}
			double r1 = slowLazySorting(a.length, a);
			double r2 = lazySorting(a.length, a);
			int t = 0;
			while (Math.abs(r1 - r2) > 0.1 && t < 10) {
				t++;
				r1 = slowLazySorting(a.length, a);
				r2 = lazySorting(a.length, a);
			}
			if (t == 10) {
				System.out.println("fail");
			}
		}
	}

	public static void lazySorting() {
		int n = in.nextInt();
		int[] a = in.nextIntArray(n);
		System.out.println(String.format("%.6f", lazySorting(n, a)));
//		System.out.println(String.format("%.6f", slowLazySorting(n, a)));
	}

	public static double slowLazySorting(int n, int[] a) {
		ArrayList<Integer> b = new ArrayList<>();
		for (int i = 0; i < a.length; i++) {
			b.add(a[i]);
		}
		Arrays.sort(a);
		int sum = 0;
		int games = 1000000;
		for (int i = 0; i < games; i++) {
			boolean wrong = false;
			int time = 0;

			for (int j = 0; j < a.length; j++) {
				if (a[j] != b.get(j)) {
					wrong = true;
					break;
				}
			}

			while (wrong) {
				wrong = false;
				time++;
				Collections.shuffle(b);
				for (int j = 0; j < a.length; j++) {
					if (a[j] != b.get(j)) {
						wrong = true;
						break;
					}
				}
				if (!wrong) {
					sum += time;
				}
			}
		}
		return sum / (double)games;
	}

	public static double lazySorting(int n, int[] a) {
		int[] f = new int[101];
		int[] b = a.clone();
		Arrays.sort(b);
		if (Arrays.equals(a, b)) {
			return 0;
		}
		for (int i = 0; i < a.length; i++) {
			f[a[i]]++;
		}
		long c = 1;
		for (int i = 1; i <= n; i++) {
			c *= i;
		}
		for (int i = 0; i < f.length; i++) {
			while (f[i] > 0) {
				c /= f[i];
				f[i]--;
			}
		}
		double p = 1.0/c;
		return 1/p;
	}

	public static void luckBalance() {
		int n = in.nextInt();
		int k = in.nextInt();
		int[] luck = new int[n];
		int[] imp = new int[n];
		for (int i = 0; i < n; i++) {
			luck[i] = in.nextInt();
			imp[i] = in.nextInt();
		}
		System.out.println(luckBalance(n, k, luck, imp));
	}

	public static long luckBalance(int n, int k, int[] luck, int[] imp) {
		ArrayList<Integer> important = new ArrayList<>();
		long balance = 0;
		for (int i = 0; i < imp.length; i++) {
			if (imp[i] == 1) {
				important.add(luck[i]);
			} else {
				balance += luck[i];
			}
		}
		Collections.sort(important);
		Collections.reverse(important);
		for (int i = 0; i < important.size(); i++) {
			if (i < k) {
				balance += important.get(i);
			} else {
				balance -= important.get(i);
			}
		}
		return balance;
	}

	public static void kangaroo() {
		int x1 = in.nextInt();
		int v1 = in.nextInt();
		int x2 = in.nextInt();
		int v2 = in.nextInt();
		if (kangaroo(x1, v1, x2, v2)) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}

	public static boolean kangaroo(int x1, int v1, int x2, int v2) {
		int dx = x1-x2;
		int dv = v2-v1;
		if (dv == 0) {
			return dx == 0;
		}
		if (((Math.abs(dx) % Math.abs(dv)) == 0) && dx / (double)dv > 0) {
			return true;
		} else {
			return false;
		}
	}

	@SuppressWarnings("serial")
	public static class Counter<T> extends HashMap<T, Integer> {
		public Counter() {
			super();
		}
		public void add(T key) {
			this.add(key, 1);
		}
		public void add(T key, int count) {
			Integer i = this.get(key);
			if (i == null) {
				this.put(key, count);
			} else {
				this.put(key, i+count);
			}
		}
	}

	public static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		public int nextInt() {return Integer.parseInt(next());}
		public long nextLong() {return Long.parseLong(next());}
		public double nextDouble() {return Double.parseDouble(next());}
		public long[] nextLongArray(int n) {
			long[] a = new long[n];
			for (int i = 0; i < a.length; i++) a[i] = this.nextLong();
			return a;
		}
		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < a.length; i++) a[i] = this.nextInt();
			return a;
		}
	}
}


import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Zyflair Griffane
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		PandaScanner in = new PandaScanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		D solver = new D();
		solver.solve(1, in, out);
		out.close();
	}
}

class D {
    final int MAX = 2520;
    long[][][] memo = new long[19][48][MAX];
    int[] idx = new int[MAX + 1];
    int[] digit = new int[19];
    public void solve(int testNumber, PandaScanner in, PrintWriter out) {

        for (int i = 0; i < 19; i++) {
            for (int j = 0; j < 48; j++) {
                Arrays.fill(memo[i][j], -1);
            }
        }
        for (int i = 1; i < MAX + 1; i++) {
            idx[i] = idx[i - 1] + (MAX % i == 0 ? 1 : 0);
        }

        int t = in.nextInt();
        for (int i = 0; i < t; i++) {
            long l = in.nextLong();
            long r = in.nextLong();
            out.println(getBeautiful(r) - getBeautiful(l - 1));
        }
    }

    public long getBeautiful(long x) {
        int length = 0;
        for (; x > 0; length++) {
            digit[length] = (int) (x % 10);
            x /= 10;
        }
        return recurse(length - 1, 1, 0, false);
    }

    public long recurse(int pow, int lcm, int mod, boolean under) {
        if (pow == -1) {
            return mod % lcm == 0 ? 1 : 0;
        }
        if (under && memo[pow][idx[lcm]][mod] > -1) {
            return memo[pow][idx[lcm]][mod];
        }
        int limit = under ? 9 : digit[pow];
        long res = 0;
        for (int i = 0; i <= limit; i++) {
            res += recurse(pow - 1, i < 2 ? lcm : (i * lcm / gcd(i, lcm)), (mod * 10 + i) % MAX, under || i < limit);
        }
        return under ? memo[pow][idx[lcm]][mod] = res : res;
    }

    public int gcd(int a, int b) {
        return b == 0 ? a : gcd(b, a % b);
    }
}

class PandaScanner {
    public BufferedReader br;
    public StringTokenizer st;
    public InputStream in;

    public PandaScanner(InputStream in) {
        br = new BufferedReader(new InputStreamReader(this.in = in));
    }

    public String nextLine() {
        try {
            return br.readLine();
        }
        catch (Exception e) {
            return null;
        }
    }

    public String next() {
        if (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(nextLine().trim());
            return next();
        }
        return st.nextToken();
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    }


import java.io.*;
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.fill;
import static java.util.Arrays.binarySearch;
import static java.util.Arrays.sort;

public class Main {
	public static void main(String[] args) throws IOException {
		new Thread(null, new Runnable() {
			public void run() {
				try {
					try {
						if (new File("input.txt").exists())
							System.setIn(new FileInputStream("input.txt"));
					} catch (SecurityException e) {}
					new Main().run();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}, "1", 1L << 24).start();
	}

	BufferedReader in;
	PrintWriter out;
	StringTokenizer st = new StringTokenizer("");

	int LCM = 5 * 7 * 8 * 9;
	int MAXL = 18;
	int MAXM = 1 << 8;
	long[] pow10 = new long [MAXL + 1];
	int[] lcm = new int [MAXM];
	long[][][] dp = new long [MAXL + 1][LCM][MAXM];
	long[] count = new long [MAXL + 1];
	long[][] cnt = new long [10][MAXL + 1];

	void run() throws IOException {
		pow10[0] = 1L;
		for (int l = 1; l < MAXL; l++)
			pow10[l] = pow10[l - 1] * 10L;
		for (int i = 0; i < MAXM; i++)
			lcm[i] = lcm(i);
		dp[0][0][0] = 1L;
		for (int l = 0; l < MAXL; l++)
			for (int r = 0; r < LCM; r++)
				for (int m = 0; m < MAXM; m++) {
					if (dp[l][r][m] == 0L)
						continue;
					for (int d = 0; d < 10; d++) {
						if (d == 0) {
							dp[l + 1][r][m] += dp[l][r][m];
							if (m == 0 || r % lcm[m] == 0)
								cnt[d][l] += dp[l][r][m];
						} else if (d == 1) {
							int nr = (int) ((pow10[l] * d + r) % LCM);
							dp[l + 1][nr][m] += dp[l][r][m];
							if (m == 0 || nr % lcm[m] == 0)
								cnt[d][l] += dp[l][r][m];
						}else {
							int nr = (int) ((pow10[l] * d + r) % LCM);
							int nm = m | (1 << (d - 2));
							dp[l + 1][nr][nm] += dp[l][r][m];
							if (nm == 0 || nr % lcm[nm] == 0)
								cnt[d][l] += dp[l][r][m];
						}
					}
				}
		for (int l = 0; l <= MAXL; l++)
			for (int r = 0; r < LCM; r++)
				for (int m = 0; m < MAXM; m++)
					if (m == 0 || r % lcm[m] == 0)
						count[l] += dp[l][r][m];
//		System.out.println(Arrays.toString(count));

		in = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);

		for (int T = nextInt(); T --> 0; )
			out.println(solve(nextLong(), nextLong()));

		out.close();
	}

	long solve(long l, long r) {
		return count(r) - count(l - 1);
	}

	long[][][] cdp = new long [MAXL + 1][LCM][MAXM];

	long count(long x) {
		for (long[][] a : cdp)
			for (long[] b : a)
				fill(b, 0);
		cdp[0][0][0] = 1L;
		long t = x;
		for (int l = 0; t > 0L; l++, t /= 10L) {
			int cd = (int) (t % 10L);
			for (int r = 0; r < LCM; r++)
				for (int m = 0; m < MAXM; m++) {
					if (cdp[l][r][m] == 0L && dp[l][r][m] == 0L)
						continue;
					for (int d = 0; d < cd; d++) {
						if (d == 0) {
							cdp[l + 1][r][m] += dp[l][r][m];
						} else if (d == 1) {
							int nr = (int) ((pow10[l] * d + r) % LCM);
							cdp[l + 1][nr][m] += dp[l][r][m];
						} else {
							int nr = (int) ((pow10[l] * d + r) % LCM);
							int nm = m | (1 << (d - 2));
							cdp[l + 1][nr][nm] += dp[l][r][m];
						}
					}
					if (cd == 0) {
						cdp[l + 1][r][m] += cdp[l][r][m];
					} else if (cd == 1) {
						int nr = (int) ((pow10[l] * cd + r) % LCM);
						cdp[l + 1][nr][m] += cdp[l][r][m];
					} else {
						int nr = (int) ((pow10[l] * cd + r) % LCM);
						int nm = m | (1 << (cd - 2));
						cdp[l + 1][nr][nm] += cdp[l][r][m];
					}
				}
		}
		long ret = 0L;
		int len = len(x);
		for (int r = 0; r < LCM; r++)
			for (int m = 0; m < MAXM; m++)
				if (m == 0 || r % lcm[m] == 0)
					ret += cdp[len][r][m];
		return ret;
	}

	int len(long x) {
		int ret = 0;
		while (x > 0L) {
			ret++;
			x /= 10L;
		}
		return ret;
	}

	int[] lst = new int [10];
	int lcm(int mask) {
		int sz = 0;
		for (int i = 0; i < 8; i++)
			if ((mask | (1 << i)) == mask)
				lst[sz++] = i + 2;
		if (sz == 0)
			return 0;
		int lcm = lst[0];
		for (int i = 1; i < sz; i++)
			lcm = lcm(lcm, lst[i]);
		return lcm;
	}

	int lcm(int a, int b) {
		return a / gcd(a, b) * b;
	}

	int gcd(int a, int b) {
		while (a > 0 && b > 0)
			if (a > b)
				a %= b;
			else
				b %= a;
		return a + b;
	}

	String nextToken() throws IOException {
		while (!st.hasMoreTokens()) {
			st = new StringTokenizer(in.readLine());
		}

		return st.nextToken();
	}

	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}
}


import java.util.*;
import java.io.*;
public class Problem {
	public static void main(String[] args) throws IOException{
		BufferedReader in= new BufferedReader(new InputStreamReader(System.in));
		PrintWriter out= new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

		int s=Integer.parseInt(in.readLine());
		String st=in.readLine();
		List<Character> lista=new ArrayList<>();
		int i;
		char mayor='a';
		for(i=0;i<s;i++) {
			char aux=st.charAt(i);
			lista.add(aux);
			if(aux>mayor)
				mayor=aux;
		}
		if(s==1)
			out.append("0\n");
		else {
			int ans=0;
			proceso:while(true){
				for(i=0;i<lista.size();i++) {
					if(mayor!='a'&&lista.get(i)==mayor) {
						if(i==0) {
							if(lista.get(i+1)==mayor-1) {
								lista.remove(i);
								ans++;
								i=0;
								continue proceso;
							}
						}else if(i==lista.size()-1) {
							if(lista.get(i-1)==mayor-1) {
								lista.remove(i);
								ans++;
								i=0;
								continue proceso;
							}
						}
						else if(lista.get(i-1)==mayor-1||lista.get(i+1)==mayor-1) {
							lista.remove(i);
							ans++;
							i=0;
							continue proceso;
						}
					}
				}
				if(mayor=='a') {
					break proceso;
				}
				else {
					mayor--;
					continue proceso;
				}

			}
			out.append(ans+"\n");
		}
		out.flush();
		in.close();
		out.close();
	}

}


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package robotsequence;

import java.util.Scanner;

/**
 *
 * @author lucian
 */
public class RobotSequence {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = Integer.parseInt(in.nextLine());
        String s = in.nextLine();

        int c = 0;
        for(int i=0;i<s.length();++i) {

            int h = 0;
            int v = 0;
            switch(s.charAt(i)) {
                case 'U': v += 1; break;
                case 'D': v -= 1; break;
                case 'L': h += 1; break;
                case 'R': h -= 1; break;
            }
            for(int j = i+1;j<s.length();++j) {
                switch(s.charAt(j)) {
                    case 'U': v += 1; break;
                    case 'D': v -= 1; break;
                    case 'L': h += 1; break;
                    case 'R': h -= 1; break;
                }

                if(h == 0 && v == 0)
                    ++c;
            }
        }

        System.out.println(c);
    }

}


import java.util.List;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.ArrayList;
import java.io.PrintStream;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Reader;
import java.io.Writer;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Nipuna Samarasekara
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		FastScanner in = new FastScanner(inputStream);
		FastPrinter out = new FastPrinter(outputStream);
		TaskC solver = new TaskC();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskC {
    /////////////////////////////////////////////////////////////
    public void solve(int testNumber, FastScanner in, FastPrinter out) {
    boolean[] isP= MathUtils.genPrimesBoolean(100009);
    int[] A= new int[100001];
        for (int i = 0; i < 100001 ; i++) {
          if(!isP[i]&&i%2==0){
              for (int j = 2; j <= i/2 ; j++) {
               if(isP[j]&&isP[i-j]){
                   A[i]=j;
                   break;
               }
              }

          }
        }
        //deb(A);
        int N=in.nextInt();
        int[] xx= new int[N];
        int[] pos= new int[N];
        for (int i = 0; i < N; i++) {
           int tt=in.nextInt()-1;
            pos[tt]=i;
            xx[i]=tt;
        }
     StringBuilder sb= new StringBuilder();
     int ct=0;
        for (int i = 0; i < N; i++) {
          int gap=pos[i]-i+1;
            int a,b,ta,tb;
            if(gap!=1){
                if(isP[gap]){
                   // swap
                    a=i;b=pos[i];
                    ct++;
                    sb.append((Math.min(a,b)+1)+" "+(Math.max(a,b)+1)+"\n");
                    tb=xx[b];ta=xx[a];
                    xx[b]=ta;
                    xx[a]=tb;
                    pos[ta]=b;
                    pos[tb]=a;

                }

                else if((gap+1)%2==0){
                    a=i+A[gap+1]-1;b=pos[i];
                    ct++;
                    sb.append((Math.min(a,b)+1)+" "+(Math.max(a,b)+1)+"\n");
                    tb=xx[b];ta=xx[a];
                    xx[b]=ta;
                    xx[a]=tb;
                    pos[ta]=b;
                    pos[tb]=a;

                    a=i;b=pos[i];
                    ct++;
                    sb.append((Math.min(a,b)+1)+" "+(Math.max(a,b)+1)+"\n");
                    tb=xx[b];ta=xx[a];
                    xx[b]=ta;
                    xx[a]=tb;
                    pos[ta]=b;
                    pos[tb]=a;

                }
                else{
                    a=pos[i];b=pos[i]-1;
                    ct++;
                    sb.append((Math.min(a,b)+1)+" "+(Math.max(a,b)+1)+"\n");
                    tb=xx[b];ta=xx[a];
                    xx[b]=ta;
                    xx[a]=tb;
                    pos[ta]=b;
                    pos[tb]=a;

                    gap=pos[i]-i+1;
                    a=i+A[gap+1]-1;b=pos[i];
                    ct++;
                    sb.append((Math.min(a,b)+1)+" "+(Math.max(a,b)+1)+"\n");
                    tb=xx[b];ta=xx[a];
                    xx[b]=ta;
                    xx[a]=tb;
                    pos[ta]=b;
                    pos[tb]=a;

                    a=i;b=pos[i];
                    ct++;
                    sb.append((Math.min(a,b)+1)+" "+(Math.max(a,b)+1)+"\n");
                    tb=xx[b];ta=xx[a];
                    xx[b]=ta;
                    xx[a]=tb;
                    pos[ta]=b;
                    pos[tb]=a;

                }

            }
        }
        out.println(ct);
        out.println(sb.toString());

    }
}

class FastScanner extends BufferedReader {

    public FastScanner(InputStream is) {
        super(new InputStreamReader(is));
    }

    public int read() {
        try {
            int ret = super.read();
//            if (isEOF && ret < 0) {
//                throw new InputMismatchException();
//            }
//            isEOF = ret == -1;
            return ret;
        } catch (IOException e) {
            throw new InputMismatchException();
        }
    }

    static boolean isWhiteSpace(int c) {
        return c >= 0 && c <= 32;
    }

    public int nextInt() {
        int c = read();
        while (isWhiteSpace(c)) {
            c = read();
        }
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        int ret = 0;
        while (c >= 0 && !isWhiteSpace(c)) {
            if (c < '0' || c > '9') {
                throw new NumberFormatException("digit expected " + (char) c
                        + " found");
            }
            ret = ret * 10 + c - '0';
            c = read();
        }
        return ret * sgn;
    }

    public String readLine() {
        try {
            return super.readLine();
        } catch (IOException e) {
            return null;
        }
    }

}

class FastPrinter extends PrintWriter {

    public FastPrinter(OutputStream out) {
        super(out);
    }

    public FastPrinter(Writer out) {
        super(out);
    }

}

class MathUtils {

    public static boolean[] genPrimesBoolean(int n) {
        boolean[] isPrime = new boolean[n];
        Arrays.fill(isPrime, true);
        isPrime[0] = isPrime[1] = false;
        for (int i = 2; i * i < n; i++) {
            if (!isPrime[i]) {
                continue;
            }
            for (int j = i * i; j < n; j += i) {
                isPrime[j] = false;
            }
        }
        return isPrime;
    }

}


import java.math.BigInteger;
import java.util.Scanner;

public class foodOnThePlane {

	public static void calctime(String str) {

		String temp=str.substring(0,str.length()-1);
		long n=Long.parseLong(temp);

		long flag=0;
		for( int i=0; ;i++)
		{
			if(4*i>=n)
			{
				flag=i-1;
				break;
			}
		}

		long k=n-(4*flag);

		long time=flag*16;
		if(k==2 || k==4)
		{
			time=time+7;
		}

		Character ch=str.charAt(str.length()-1);

		if(ch=='f')
			time=time+1;

		else if(ch=='e')
			time=time+2;

		else if(ch=='d')
			time=time+3;

		else if(ch=='a')
			time=time+4;

		else if(ch=='b')
			time=time+5;

		else if(ch=='c')
			time=time+6;

		System.out.println(time);

	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub

		Scanner s=new Scanner(System.in);

		String str=s.next();
		calctime(str);

	}

}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author creativitRy
 */
public class Main
{
	public static void main(String[] args)
	{
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		Scanner in = new Scanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskB solver = new TaskB();
		solver.solve(1, in, out);
		out.close();
	}

	static class TaskB
	{
		public void solve(int testNumber, Scanner in, PrintWriter out)
		{
			String temp = in.next();
			long num = Long.parseLong(temp.substring(0, temp.length() - 1));
			char pos = temp.charAt(temp.length() - 1);

			long temp2 = 1;
			long temp3 = 0;
			while (true)
			{
				if (temp2 == num || temp2 + 2 == num)
					break;

				if ((temp2 & 1) == 0)
				{
					temp2 += 3;
					temp3 += 9;
				}
				else
				{
					temp2++;
					temp3 += 7;
				}

			}

			out.println(temp3 + change(pos));
		}

		public int change(char c)
		{
			if (c == 'a')
				return 4;
			else if (c == 'b')
				return 5;
			else if (c == 'c')
				return 6;
			else if (c == 'd')
				return 3;
			else if (c == 'e')
				return 2;
			return 1;
		}

	}
}


import static java.lang.System.in;
import static java.lang.System.out;

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

public class C351brackets {
	static final double EPS = 1e-10;
	static final int INF = 1 << 28;
	static final double PI = Math.PI;

	public static Scanner sc = new Scanner(in);
	StringBuilder sb = new StringBuilder();
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

	public void run() throws IOException {
		String input;
		String[] inputArray;
		input = br.readLine();
		inputArray = input.split(" ");

		int n = Integer.valueOf(inputArray[0]);
		int m = Integer.valueOf(inputArray[1]);
		int [] a = new int[n];
		int [] b = new int[n];
		input = br.readLine();
		inputArray = input.split(" ");
		for (int i=0; i<n; i++) a[i] = Integer.valueOf(inputArray[i]);
		input = br.readLine();
		inputArray = input.split(" ");
		for (int i=0; i<n; i++) b[i] = Integer.valueOf(inputArray[i]);
/*
		int [][] opt = new int[n+1][2*n+1];
		for (int i=0; i<=n; i++)
			for (int j=0; j<=2*n; j++)
				opt[i][j] = INF;
		//opt[i][j]- i is {max")"}, j is total +n;
		for (int i=0; i<(1<<n); i++){
			int total=0;
			int close =0;
			int value = 0;
			for (int k = i, j=0; j<n; j++,k>>=1)
				if (k%2==0) { //closed
					total--;
					close = Math.min(close,total);
					value+=b[j];
				} else {
					total++;//opened
					value+=a[j];
				}
			opt[-close][total+n]=Math.min(opt[-close][total+n], value);
		}
		*/
		int [] dp = new int[2*n+1];
		int [] t = new int[2*n+1];
		dp[0]=0;
		for (int j=1; j<=2*n; j++)
			dp[j] = INF;
		int x,y;
		for (int i=0; i<n*m; i++){
			x = a[i%n];
			y = b[i%n];
			t[0] = dp[1] +y;
			for (int j=1; j<2*n; j++)
				t[j] = Math.min(dp[j+1] +y, dp[j-1]+x);
			t[2*n] = dp[2*n-1]+x;
			for (int j=0; j<=2*n; j++)
				dp[j] = t[j];
		}
		ln(dp[0]);
	}

	public static void main(String[] args) throws IOException {
		new C351brackets().run();
	}
	public static void ln(Object obj) {
		out.println(obj);
	}
}


import java.util.*;

public class Program2 {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		System.out.printf("%d", (int)((Math.floor(n/2) + 1) * Math.ceil(n/2));
	}
}


import java.io.*;
import java.math.BigInteger;
import java.util.*;

public class CodeForces {
    static boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;

    void runCase(int caseNum) throws IOException {
        long p = nextLong();
        long d = nextLong();

        long res = p;
        BigInteger dd = BigInteger.TEN;

        long t = p;
        while (t % 10 == 9) {
            t /= 10;
            dd = dd.multiply(BigInteger.TEN);
        }
        while (true) {
            if (dd.compareTo(BigInteger.valueOf(p)) > 0)
                break;
            long da = dd.longValue();
            t = ((long)(p / da)) * da - 1;
            if (p - t >= d)
                break;
            res = t;
        }
        out.println(res);
    }

    public static void main(String[] args) throws IOException {
        if (ONLINE_JUDGE){
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
        }else{
            in = new BufferedReader(new FileReader("input.txt"));
            out = new PrintWriter("output.txt");
        }
        new CodeForces().runIt();
        out.flush();
        out.close();
        return;
    }

    static BufferedReader in;
    private StringTokenizer st;
    static PrintWriter out;

    String next() throws IOException {
        while (!st.hasMoreTokens()) {
            String line = in.readLine();
            if (line == null) {
                return null;
            }
            st = new StringTokenizer(line, " ");
        }
        return st.nextToken();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }

    long nextLong() throws IOException {
        return Long.parseLong(next());
    }

    void runIt() throws IOException {
        st = new StringTokenizer("");

//        int N = nextInt();
//        for (int i = 0; i < N; i++) {
//            runCase(i + 1);
//        }
        runCase(0);

        out.flush();
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;

public class H2019D {

	static long cons = 1000000007;

	public static void main(String[] args) throws NumberFormatException, IOException {

		BufferedReader sc = new BufferedReader(new InputStreamReader(System.in));

		String[] dir = sc.readLine().split(" ");
		long n = Long.parseLong(dir[0]);
		long k = Long.parseLong(dir[1]);

		long finalans = 1;

		ArrayList<Long> factors = primeFactors(n);

		Map<Long, Long> map = new HashMap<Long, Long>();

		for(long f:factors) {
			if(map.get(f) == null) {
				map.put(f,1l);
			}
			else {
				map.put(f, map.get(f) + 1);
			}
		}

		long i = 0;
		Iterator<Entry<Long, Long>> it = map.entrySet().iterator();
		while (it.hasNext()) {
		    Entry<Long, Long> pair = it.next();
		    long factor = pair.getKey();
		    long count = pair.getValue();

		    long ans = expected(factor, count, k);
		    finalans *= ans;
		    finalans %= cons;
		}

		System.out.print(finalans);
	}

	public static long expected(long factor, long count, long k) {
		long[] odds = new long[(int) count+1];
		long[] vals = new long[(int) count+1];
		long mult = 1;
		odds[odds.length - 1] = 1l;
		vals[0] = 1l;
		long sum = 1;
		for(int i=1; i<=count; i++) {
			mult *= (factor)%cons;
			//sum += mult;sum%=cons;
			vals[i] = mult;
			//odds[i] = (sum * inv(i+1))%cons;
		}

		//System.out.println(Arrays.toString(vals));

		for(int j=0; j<k; j++) {
			//System.out.println(Arrays.toString(odds));

			long[] newodds = new long[(int) count+1];
			for(int oldindex = 0; oldindex <= count; oldindex++) {
				for(int newindex = 0; newindex <= oldindex; newindex++) {
					newodds[newindex] += (odds[oldindex]*inv(oldindex+1))%cons;
					newodds[newindex] %= cons;
				}
			}
			for(int index = 0; index<=count; index++) {
				odds[index] = newodds[index];
			}
		}

		long ans = 0;

		for(int i=0; i<=count; i++) {
			odds[i] *= vals[i];
			odds[i] %= cons;

			ans += odds[i];
			ans %= cons;
		}

		return ans;
	}

	public static ArrayList<Long> primeFactors(long n) {
		ArrayList<Long> list = new ArrayList<Long>();
        while (n%2==0)
        {
            list.add(2l);
            n /= 2;
        }
        for (int i = 3; i <= Math.sqrt(n); i+= 2)
        {
            while (n%i == 0)
            {
            	list.add((long)i);
                n /= i;
            }
        }
        if (n > 2)
        	list.add(n);

        return list;
    }

	public static long inv(long n) {
		return BigInteger.valueOf(n).modInverse(BigInteger.valueOf(1000000007)).longValue();
	}
}

/*
BufferedReader sc = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(sc.readLine());
String[] t = sc.readLine().split(" ");
int[] list = new int[n];
for(int x=0; x<n; x++){
	list[x] = Integer.parseInt(t[x]);
}

String[] dir = sc.readLine().split(" ");
int a = Integer.parseInt(dir[0]);
int b = Integer.parseInt(dir[1]);
int c = Integer.parseInt(dir[2]);
int d = Integer.parseInt(dir[3]);
int e = Integer.parseInt(dir[4]);
int n = Integer.parseInt(sc.readLine());
*/


import java.util.*;

public class d
{
   public static long mod = 1000000007;
   public static long[] invs = new long[60];
   public static void main(String[] Args)
   {
      for (int i = 1; i < 60; i++)
      {
         invs[i] = modInv(i, mod);
      }
      Scanner sc = new Scanner(System.in);
      long x = sc.nextLong();
      int iter = sc.nextInt();
      ArrayList<Long> derp = doit(x);
      long ans = 1;
      for (int i = 0; i < derp.size(); i+=2){
         ans *= get(derp.get(i), derp.get(i + 1), iter);
         ans %= mod;
      }
      System.out.println(ans);
   }

   public static ArrayList<Long> doit(long x)
   {
      ArrayList<Long> ret = new ArrayList<Long>();
      for (int i = 2; i * i <= x; i++)
      {
         long p = 0;
         while (x % i == 0)
         {
            p++;
            x /= i;
         }
         if (p != 0){
            ret.add((long)i);
            ret.add(p);
         }
      }
      if (x != 1){
         ret.add(x);
         ret.add(1l);
      }
      return ret;
   }

   public static long get(long p, long pow, int iter)
   {
      pow++;
      int n = (int)pow;
      long[] vs = new long[n];
      vs[0] = 1;
      for (int i = 1; i < n; i++)
         vs[i] = vs[i - 1] * p;

      long[] newtab = new long[n];

      long[][] mat = new long[n][n];
      for (int j = 0; j < n; j++)
         for (int k = 0; k <= j; k++)
            mat[j][k] = invs[j + 1];

      mat = matExpo(mat, iter, mod);

      //System.out.println(Arrays.deepToString(mat));
      // System.out.println(Arrays.toString(vs));

      for (int i = 0; i < 1; i++)
         for (int k = 0; k < n; k++)
            newtab[k] += mat[n - 1][k];

      long ans = 0;
      for (int i = 0; i < n; i++)
      {
         ans += (vs[i] % mod) * newtab[i];
         ans %= mod;
      }
      return ans;
   }

   public static long[][] matExpo(long[][] mat, long pow, long mod)
   {
      int n = mat.length;
      if (pow == 0)
      {
         long[][] ret = new long[n][n];
         for (int i = 0; i < n; i++)
         {
            ret[i][i] = 1 % mod;
         }
         return ret;
      }
      if (pow == 1)
      {
         for (int i = 0; i < n; i++)
            for (int j = 0; j < n; j++)
               mat[i][j] %= mod;
         return mat;
      }

      long[][] tmp = matExpo(mat, pow / 2, mod);
      tmp = mult(tmp, tmp, mod);
      if (pow % 2 == 1)
         tmp = mult(tmp, mat, mod);
      return tmp;
   }

   public static long[][] mult(long[][] a, long[][] b, long mod)
   {
      int n = a.length;
      long[][] ret = new long[n][n];
      for (int i = 0; i < n; i++)
         for (int j = 0; j < n; j++)
            for (int k = 0; k < n; k++){
               ret[i][j] += a[i][k] * b[k][j];
               ret[i][j] %= mod;
            }
      return ret;
   }

   public static ArrayList<Long> getDiv(long x){
      ArrayList<Long> ret = new ArrayList<Long>();
      for (long y = 1; y * y <= x; y++)
      {
         if (x % y == 0)
         {
            ret.add(y);
            if (y != x / y)
               ret.add(x / y);
         }
      }

      return ret;
   }

   public static long modInv(long x, long mod)
   {
      return modExpo(x, mod - 2, mod);
   }

   public static long modExpo(long base, long exp, long mod)
   {
      if (exp == 0)
         return 1 % mod;
      if (exp == 1)
         return base % mod;

      long tmp = modExpo(base, exp / 2, mod);
      tmp = tmp * tmp;
      tmp %= mod;
      if (exp % 2 == 1){
         tmp *= base;
         tmp %= mod;
      }
      return tmp;
   }
}