import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.function.*;
import java.util.regex.*;
import java.util.stream.*;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toList;

public class Main{

    static long MOD = 1_000_000_007L;
    //static long MOD = 998_244_353L;
    //static long MOD = 1_000_000_033L;
    static long inv2 = (MOD + 1) / 2;

    static int[][] dir = new int[][]{{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
    static long lMax = 0x3f3f3f3f3f3f3f3fL;
    static int iMax = 0x3f3f3f3f;
    static HashMap <Long, Long> memo = new HashMap();
    static MyScanner sc = new MyScanner();
    //static ArrayList <Integer> primes;

    static int nn = 300000;
    static long[] pow2;
    static long [] fac;
    static long [] pow;
    static long [] inv;
    static long [] facInv;
    static int[] base;
    static int[] numOfDiffDiv;
    static int[] numOfDiv;
    static ArrayList <Integer> primes;
    //static int[] primes;
    static int ptr = 0;
    static boolean[] isPrime;

    //-----------PrintWriter for faster output---------------------------------
    public static PrintWriter out;
    public static void main(String[] args) {
        out = new PrintWriter(new BufferedOutputStream(System.out));
        // Start writing your solution here. -------------------------------------

        /*fac = new long[nn + 1];
        fac[1] = 1;
        for(int i = 2; i <= nn; i++)
            fac[i] = fac[i - 1] * i % MOD;*/

        /*pow2 = new long[nn + 1];
        pow2[0] = 1L;
        for(int i = 1; i <= nn; i++)
            pow2[i] = pow2[i - 1] * 2L;*/

        /*inv = new long[nn + 1];
        inv[1] = 1;
        for (int i = 2; i <= nn; ++i)
            inv[i] = (MOD - MOD / i) * inv[(int)(MOD % i)] % MOD;*/

        /*facInv = new long[nn + 1];
        facInv[0] = facInv[1] = 1;
        for (int i = 2; i <= nn; ++i)
            facInv[i] = facInv[i - 1] * inv[i] % MOD;*/

        /*numOfDiffDiv = new int[nn + 1];
        for(int i = 2; i <= nn; i++)
            if(numOfDiffDiv[i] == 0)
                for(int j = i; j <= nn; j += i)
                    numOfDiv[j] ++;*/

        /*numOfDiv = new int[nn + 1];
        numOfDiv[1] = 1;
        for(int i = 2; i <= nn; i++) {
            for(int j = 2; j * j <= i; j++) {
                if(i % j == 0) {
                    numOfDiv[i] = numOfDiv[i / j] + 1;
                    break;
                }
            }
        }*/

        //primes = sieveOfEratosthenes(100001);

        /*
        int t = 1;
        //t = sc.ni();
        while(t-- > 0) {
            //boolean res = solve();
            //out.println(res ? "YES" : "NO");
            long res = solve();
            out.println(res);
        }*/

        int t = 1, tt = 0;
        t = sc.ni();
        for(int i = 1; i <40000; i++) squares.add(i * i);
        while(tt++ < t) {
            boolean res = solve();
            //out.println("Case #" + tt + ": " + res);
            //out.println(res ? "YES" : "NO");
        }
        out.close();
    }
    static HashSet <Integer> squares = new HashSet();

    static boolean solve() {
        /*String s = sc.nextLine();
        char[] c = s.toCharArray();
        int n = c.length;*/
        //int n = sc.ni();
        //long[] a =  new long[n];
        //for(int i = 0; i < n; i++) a[i] = sc.nl();
        long res = 0;
        int n = sc.ni();
        long m = sc.nl();
        long[][][] dp = new long[2][n + 3][n + 3];
        long[][][] dp2 = new long[2][n + 3][n + 3];
        dp[0][2][1] = dp[1][2][2] = dp2[0][1][1] = 1L;
        for(int i = 3; i <= n; i++) {
            long[][] bef = dp[0];
            long[][] aft = dp[1];
            long[][] nbef = new long[n + 3][n + 3];
            long[][] naft = new long[n + 3][n + 3];
            for(int len = 1; len <= i; len++) {
                for(int ind = 1; ind <= len; ind++) {
                    nbef[len + 1][1] += bef[len][ind];
                    nbef[len + 1][ind + 1] -= bef[len][ind];
                    naft[len + 1][ind + 1] += bef[len][ind];
                    //naft[len + 1][len + 2] -= bef[len][ind];
                    naft[len + 1][ind + 1] += aft[len][ind];
                    //naft[len + 1][len + 2] -= aft[len][ind];
                    nbef[len + 1][1] += dp2[0][len][ind] + dp2[1][len][ind];
                    //nbef[len + 1][len + 2] -= dp2[0][len][ind] + dp2[1][len][ind];
                }
            }
            for(int len = 1; len <= i; len++) {
                for(int ind = 1; ind <= len; ind ++) {
                    nbef[len][ind] = (nbef[len][ind] + nbef[len][ind - 1] + 100L * m) % m;
                    naft[len][ind] = (naft[len][ind] + naft[len][ind - 1] + 100L * m) % m;
                }
            }
            dp2 = dp;
            dp = new long[][][]{nbef, naft};
        }
        for(long[] row: dp[0])
            for(long i : row)
                res += i;
        for(long[] row: dp[1])
            for(long i : row)
                res += i;
            out.println(res % m);
        return false;
    }

    // edges to adjacency list by uwi
    public static int[][] packU(int n, int[] from, int[] to) {
        return packU(n, from, to, from.length);
    }

    public static int[][] packU(int n, int[] from, int[] to, int sup) {
        int[][] g = new int[n][];
        int[] p = new int[n];
        for (int i = 0; i < sup; i++) p[from[i]]++;
        for (int i = 0; i < sup; i++) p[to[i]]++;
        for (int i = 0; i < n; i++) g[i] = new int[p[i]];
        for (int i = 0; i < sup; i++) {
            g[from[i]][--p[from[i]]] = to[i];
            g[to[i]][--p[to[i]]] = from[i];
        }
        return g;
    }

    // tree diameter by uwi
    public static int[] diameter(int[][] g) {
        int n = g.length;
        int f0 = -1, f1 = -1, d01 = -1;
        int[] q = new int[n];
        boolean[] ved = new boolean[n];
        {
            int qp = 0;
            q[qp++] = 0; ved[0] = true;
            for(int i = 0;i < qp;i++){
                int cur = q[i];
                for(int e : g[cur]){
                    if(!ved[e]){
                        ved[e] = true;
                        q[qp++] = e;
                        continue;
                    }
                }
            }
            f0 = q[n-1];
        }
        {
            int[] d = new int[n];
            int qp = 0;
            Arrays.fill(ved, false);
            q[qp++] = f0; ved[f0] = true;
            for(int i = 0;i < qp;i++){
                int cur = q[i];
                for(int e : g[cur]){
                    if(!ved[e]){
                        ved[e] = true;
                        q[qp++] = e;
                        d[e] = d[cur] + 1;
                        continue;
                    }
                }
            }
            f1 = q[n-1];
            d01 = d[f1];
        }
        return new int[]{d01, f0, f1};
    }

    public static long c(int n, int k) {
        return (fac[n] * facInv[k] % MOD) * facInv[n - k] % MOD;
    }

    // SegmentTree range min/max query by uwi
    public static class SegmentTreeRMQ {
        public int M, H, N;
        public int[] st;

        public SegmentTreeRMQ(int n)
        {
            N = n;
            M = Integer.highestOneBit(Math.max(N-1, 1))<<2;
            H = M>>>1;
            st = new int[M];
            Arrays.fill(st, 0, M, Integer.MAX_VALUE);
        }

        public SegmentTreeRMQ(int[] a)
        {
            N = a.length;
            M = Integer.highestOneBit(Math.max(N-1, 1))<<2;
            H = M>>>1;
            st = new int[M];
            for(int i = 0;i < N;i++){
                st[H+i] = a[i];
            }
            Arrays.fill(st, H+N, M, Integer.MAX_VALUE);
            for(int i = H-1;i >= 1;i--)propagate(i);
        }

        public void update(int pos, int x)
        {
            st[H+pos] = x;
            for(int i = (H+pos)>>>1;i >= 1;i >>>= 1)propagate(i);
        }

        private void propagate(int i)
        {
            st[i] = Math.min(st[2*i], st[2*i+1]);
        }

        public int minx(int l, int r){
            int min = Integer.MAX_VALUE;
            if(l >= r)return min;
            while(l != 0){
                int f = l&-l;
                if(l+f > r)break;
                int v = st[(H+l)/f];
                if(v < min)min = v;
                l += f;
            }

            while(l < r){
                int f = r&-r;
                int v = st[(H+r)/f-1];
                if(v < min)min = v;
                r -= f;
            }
            return min;
        }

        public int min(int l, int r){ return l >= r ? 0 : min(l, r, 0, H, 1);}

        private int min(int l, int r, int cl, int cr, int cur)
        {
            if(l <= cl && cr <= r){
                return st[cur];
            }else{
                int mid = cl+cr>>>1;
                int ret = Integer.MAX_VALUE;
                if(cl < r && l < mid){
                    ret = Math.min(ret, min(l, r, cl, mid, 2*cur));
                }
                if(mid < r && l < cr){
                    ret = Math.min(ret, min(l, r, mid, cr, 2*cur+1));
                }
                return ret;
            }
        }
    }

    public static char[] rev(char[] a){char[] b = new char[a.length];for(int i = 0;i < a.length;i++)b[a.length-1-i] = a[i];return b;}

    public static double dist(double a, double b){
        return Math.sqrt(a * a + b * b);
    }

    public static long inv(long a){
        return quickPOW(a, MOD - 2);
    }

    public class Interval {
        int start;
        int end;
        public Interval(int start, int end) {
            this.start = start;
            this.end = end;
        }
    }

    public static ArrayList<Integer> sieveOfEratosthenes(int n) {
        boolean prime[] = new boolean[n + 1];
        Arrays.fill(prime, true);
        for (int p = 2; p * p <= n; p++) {
            if (prime[p]) {
                for (int i = p * 2; i <= n; i += p) {
                    prime[i] = false;
                }
            }
        }
        ArrayList<Integer> primeNumbers = new ArrayList<>();
        for (int i = 2; i <= n; i++) {
            if (prime[i]) {
                primeNumbers.add(i);
            }
        }
        return primeNumbers;
    }

    public static int lowerBound(int[] a, int v){ return lowerBound(a, 0, a.length, v); }
    public static int lowerBound(int[] a, int l, int r, int v)
    {
        if(l > r || l < 0 || r > a.length)throw new IllegalArgumentException();
        int low = l-1, high = r;
        while(high-low > 1){
            int h = high+low>>>1;
            if(a[h] >= v){
                high = h;
            }else{
                low = h;
            }
        }
        return high;
    }
    public static int rlowerBound(int[] a, int v){ return lowerBound(a, 0, a.length, v); }
    public static int rlowerBound(int[] a, int l, int r, int v)
    {
        if(l > r || l < 0 || r > a.length)throw new IllegalArgumentException();
        int low = l-1, high = r;
        while(high-low > 1){
            int h = high+low>>>1;
            if(a[h] <= v){
                high = h;
            }else{
                low = h;
            }
        }
        return high;
    }
    public static long C(int n, int m)
    {
        if(m == 0 || m == n) return 1l;
        if(m > n || m < 0) return 0l;
        long res = fac[n] * quickPOW((fac[m] * fac[n - m]) % MOD, MOD - 2) % MOD;

        return res;
    }
    public static long quickPOW(long n, long m)
    {
        long ans = 1l;
        while(m > 0)
        {
            if(m % 2 == 1)
                ans = (ans * n) % MOD;
            n = (n * n) % MOD;
            m >>= 1;
        }
        return ans;
    }
    public static long quickPOW(long n, long m, long mod)
    {
        long ans = 1l;
        while(m > 0)
        {
            if(m % 2 == 1)
                ans = (ans * n) % mod;
            n = (n * n) % mod;
            m >>= 1;
        }
        return ans;
    }

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

    static class Randomized {
        public static void shuffle(int[] data) {
            shuffle(data, 0, data.length - 1);
        }

        public static void shuffle(int[] data, int from, int to) {
            to--;
            for (int i = from; i <= to; i++) {
                int s = nextInt(i, to);
                int tmp = data[i];
                data[i] = data[s];
                data[s] = tmp;
            }
        }

        public static void shuffle(long[] data) {
            shuffle(data, 0, data.length - 1);
        }

        public static void shuffle(long[] data, int from, int to) {
            to--;
            for (int i = from; i <= to; i++) {
                int s = nextInt(i, to);
                long tmp = data[i];
                data[i] = data[s];
                data[s] = tmp;
            }
        }

        public static int nextInt(int l, int r) {
            return RandomWrapper.INSTANCE.nextInt(l, r);
        }
    }

    static class RandomWrapper {
        private Random random;
        public static final RandomWrapper INSTANCE = new RandomWrapper(new Random());

        public RandomWrapper() {
            this(new Random());
        }

        public RandomWrapper(Random random) {
            this.random = random;
        }

        public int nextInt(int l, int r) {
            return random.nextInt(r - l + 1) + l;
        }

    }

    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        int ni() {
            return Integer.parseInt(next());
        }
        long nl() {
            return Long.parseLong(next());
        }
        double nd() {
            return Double.parseDouble(next());
        }
        String nextLine(){
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
    //--------------------------------------------------------
}


import java.util.*;

public class Compute {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int M = sc.nextInt();
        long fact[] = new long[n+1];
        long ifact[] = new long[n+1];
        long dp[][] = new long[n+1][n+1];
        fact[1] = 1;
        ifact[1] = 1;
        dp[1][1] = 1;

        for(int i = 2; i <= n; i++) {
            fact[i] = (i*fact[i-1]) % M;
            ifact[i] = (ifact[M % i]*(M - M/i)) % M;
            dp[i][i] = (dp[i-1][i-1] * 2) % M;
        }

        for(int i = 3; i <= n; i++) {
            for(int j = i/2 + 1; j <= i-1; j++) {
                for(int k = 2; k <= i-1 && ((j - k + 1) > (i - k)/2); k++) {
                    dp[i][j] += ((((dp[k-1][k-1]*dp[i-k][j-k+1] % M)*fact[j] % M)*ifact[k-1] % M)*ifact[j-k+1] % M);
                }
            }
        }

        long sum = 0;
        for(int i = n/2 + 1; i <= n; i++) {

            sum = (sum + dp[n][i]) % M;
        }

        System.out.println(sum % M);
    }
}


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

public class Main{

    public static void main (String [] args){
        Scanner scan = new Scanner(System.in);
        long k = scan.nextLong();
        solve(k);
    }

    public static void solve (long k){
        BigInteger mod = BigInteger.valueOf(1000000007);
        long nodes = (long)Math.pow(2, k)-2;
        BigInteger nodess = BigInteger.valueOf(nodes);
        BigInteger four = new BigInteger("4");
        BigInteger result = four.modPow(nodess,mod);
        result = result.multiply(BigInteger.valueOf(6));
        result = result.mod(mod);
        System.out.println(result;
    }
}


import java.io.*;
import java.util.Random;
import java.util.StringTokenizer;

public class Main {

    static InputReader sc = new InputReader(System.in);
    static PrintWriter out = new PrintWriter(System.out);
    static int mod = 1000000007;
    public static void main(String[] args) throws IOException {

        int k = sc.nextInt();
        long sum = 6;
        int L = (1 << (k)) - 1;
        long[] exponent = new long[L];
        for(int i = 0; i < L; i++){
            exponent[i] = 1;
            int v = i / 2;
            if((i & 1) == 1){
                exponent[i] = 4;
            }
            exponent[i] = (exponent[i] * ((exponent[v] * exponent[v]) % mod))%mod;
        }

        sum = (sum * exponent[L - 1]) % mod;

        out.println(sum);
        out.flush();
        out.close();
    }

    private 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()); }
    }

    void shuffleArray(long[] arr){
        int n = arr.length;
        Random rnd = new Random();
        for(int i=0; i<n; ++i){
            long tmp = arr[i];
            int randomPos = i + rnd.nextInt(n-i);
            arr[i] = arr[randomPos];
            arr[randomPos] = tmp;
        }
    }

    static class Pair<K, V>{

        K key;
        V value;
        public Pair(K key, V value){
            this.key = key;
            this.value = value;
        }
    }

}


import java.util.*;
public class test{
    public static void main(System[] args){
        int n;

        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        for(int i=0;i<n;i++){
             int arr[] = new int[4];
             for(int i=0;i<arr.length;i++){
                 arr[i] = sc.nextInt();
             }
             if(((arr[0]+arr[1])==(arr[2]+arr[3])) && ((arr[0]+arr[2])==(arr[1]+arr[3])))
             {
                 if(0==(arr[0]+arr[1]+arr[2]+arr[3])){
                     System.out.println(0);
                 }else{
                     System.out.println(2);
                 }
             }
             else{
                 System.out.println(1);
             }
        }
    }
}


import java.util*;
import java.io.*;
public class Main{
   public static void main(String[] args){
      Scanner scn=new Scanner(System.in);
      int t=scn.nextInt();
      while(t-->0){
         int count=0;
         for(int i=0;i<4;i++){
            int val=scn.nextInt();
            if(val==1){
               count++;
            }
         }
         if(count==0){
            System.out.println(0);
         }else if(count==4){
            System.out.println(2);
         }else{
            System.out.println(1);
         }
      }
   }
}


import java.io.BufferedOutputStream;
import java.io.PrintWriter;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.Collection;

public class D1 extends Driver {
  public static void main(String[] args) {
    new D1().run();
  }

  @Override
  public void solveOne() {
    OutputUtils.yn(out, canSolve());
  }

  boolean canSolve() {
    int n = in.nextInt(), m = in.nextInt(), k = in.nextInt();
    if (n % 2 == 0) {
      return k % 2 == 0;
    } else {
      return (k - m / 2) % m == 0;
    }
  }
}

class Driver {
  public static final boolean LOCAL = System.getProperty("ONLINE_JUDGE") == null;

  public final PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out), LOCAL);

  public final FastScanner in = new FastScanner();

  public final void run() {
    try {
      solve();
    } finally {
      close();
    }
  }

  public void solve() {
    int tt = in.nextInt();
    while (tt-- > 0) {
      if (LOCAL) {
        out.println("--------------------------------------");
      }
      solveOne();
    }
  }

  public void solveOne() {
    throw null;
  }

  protected void close() {
    out.close();
  }

  protected void print(Object... objects) {
    for (int i = 0; i < objects.length; i++) {
      if (i > 0) {
        out.print(' ');
      }
      out.print(objects[i]);
    }
  }

  protected void println(Object... objects) {
    print(objects);
    out.println();
  }
}

class FastScanner {
  BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

  StringTokenizer st = new StringTokenizer("");

  public String next() {
    while (!st.hasMoreElements()) {
      try {
        st = new StringTokenizer(br.readLine());
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
    return st.nextToken();
  }

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

  public char nextChar() {
    return next().charAt(0);
  }

  public int[] nextArray(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++) {
      a[i] = nextInt();
    }
    return a;
  }

  public char[] nextCharArray(int n) {
    char[] a = new char[n];
    for (int i = 0; i < n; i++) {
      a[i] = nextChar();
    }
    return a;
  }

  public long[] nextLongArray(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++) {
      a[i] = nextLong();
    }
    return a;
  }

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

class OutputUtils {
  public static void yn(PrintWriter out, boolean y) {
    out.println(y ? "YES" : "NO");
  }

  public static void printMany(PrintWriter out, Object a) {
    if (a instanceof int[]) {
      printArray(out, (int[]) a);
    } else if (a instanceof long[]) {
      printArray(out, (long[]) a);
    } else if (a instanceof double[]) {
      printArray(out, (double[]) a);
    } else if (a instanceof Object[]) {
      printArray(out, (Object[]) a);
    } else if (a instanceof Collection<?>) {
      printCollection(out, (Collection<?>) a);
    } else {
      throw null;
    }
  }

  private static void printArray(PrintWriter out, long[] a) {
    for (int i = 0; i < a.length; i++) {
      if (i > 0) {
        out.print(' ');
      }
      out.print(a[i]);
    }
    out.println();
  }

  private static <E> void printArray(PrintWriter out, E[] a) {
    for (int i = 0; i < a.length; i++) {
      if (i > 0) {
        out.print(' ');
      }
      out.print(a[i]);
    }
    out.println();
  }

  private static void printArray(PrintWriter out, int[] a) {
    for (int i = 0; i < a.length; i++) {
      if (i > 0) {
        out.print(' ');
      }
      out.print(a[i]);
    }
    out.println();
  }

  private static void printArray(PrintWriter out, double[] a) {
    for (int i = 0; i < a.length; i++) {
      if (i > 0) {
        out.print(' ');
      }
      out.print(a[i]);
    }
    out.println();
  }

  private static <E> void printCollection(PrintWriter out, Collection<E> a) {
    int i = 0;
    for (E x : a) {
      if (i++ > 0) {
        out.print(' ');
      }
      out.print(x);
    }
    out.println();
  }
}

class E extends Driver {
  public static void main(String[] args) {
    new E().run();
  }

  @Override
  public void solve() {
    int n = in.nextInt();
    char[] cs = in.next().toCharArray();
    int[] pacmans, food;
    int npacman = 0, nfood = 0;
    {
      int ipacman = 0, ifood = 0;
      for (int i = 0; i < n; i++) {
        if (cs[i] == 'P') {
          npacman++;
        }
        if (cs[i] == '*') {
          nfood++;
        }
      }
      pacmans = new int[npacman];
      food = new int[nfood];
      for (int i = 0; i < n; i++) {
        if (cs[i] == 'P') {
          pacmans[ipacman++] = i;
        }
        if (cs[i] == '*') {
          food[ifood++] = i;
        }
      }
    }
    int lo = 0, hi = 3 * n;
    while (lo < hi) {
      int mid = (lo + hi) / 2;
      int leftMost = 0;
      for (int i = 0; i < npacman; i++) {
        int rightDist;
        if (pacmans[i] < food[leftMost]) {
          rightDist = mid;
        } else {
          int leftDist = pacmans[i] - food[leftMost];
          if (leftDist > mid) {
            break;
          }
          // 2 cases:
          // 1.  *...P.*   go to the right first
          // 1.  *.P...*   go to the left first
          rightDist = Math.max(mid - 2 * leftDist, (mid - leftDist) / 2);
        }
        while (leftMost < nfood && food[leftMost] <= pacmans[i] + rightDist) {
          leftMost++;
        }
        if (leftMost == nfood) {
          break;
        }
      }
      if (leftMost == nfood) {
        hi = mid;
      } else {
        lo = mid + 1;
      }
    }
    out.println(lo);
  }
}


public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int t = in.nextInt();
        while (t-- > 0) {
            int n = in.nextInt();
            int m = in.nextInt();
            int k = in.nextInt();
            if (n % 2==0&&m%2==0){
                if (k%2 == 0){
                    System.out.println("YES");
                    continue;
                }else{
                    System.out.println("NO");
                    continue;
                }
            }else if (n%2!=0&&m%2==0){
                if (k < m/2){
                    System.out.println("NO");
                    continue;
                }
                if ((m/2-k)%2!=0){
                    System.out.println("NO");
                    continue;
                }
                System.out.println("YES");
                continue;
            }else {
                int kk = m*n/2-k;
                if (kk < n/2){
                    System.out.println("NO");
                    continue;
                }
                if ((n/2-kk)%2!=0){
                    System.out.println("NO");
                    continue;
                }
                System.out.println("YES");
                continue;
            }
        }
    }
}


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

// you can compare with output.txt and expected out
public class Round791F {
	MyPrintWriter out;
	MyScanner in;

//	final static long FIXED_RANDOM;
//	static {
//		FIXED_RANDOM = System.currentTimeMillis();
//	}
	final static String IMPOSSIBLE = "IMPOSSIBLE";
	final static String POSSIBLE = "POSSIBLE";
	final static String YES = "YES";
	final static String NO = "NO";
	final static long MOD = 998244353;

    private void initIO(boolean isFileIO) {
        if (System.getProperty("ONLINE_JUDGE") == null && isFileIO) {
        	try{
	            in = new MyScanner(new FileInputStream("input.txt"));
	            out = new MyPrintWriter(new FileOutputStream("output.txt"));
        	}
        	catch(FileNotFoundException e){
        		e.printStackTrace();
        	}
        }
        else{
    		in = new MyScanner(System.in);
    	    out = new MyPrintWriter(new BufferedOutputStream(System.out));
        }
    }

	public static void main(String[] args){
//		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));

		Round791F sol = new Round791F();
		sol.run();
    }

	private void run() {
		boolean isDebug = false;
		boolean isFileIO = true;
		boolean hasMultipleTests = false;

		initIO(isFileIO);

		int t = hasMultipleTests? in.nextInt() : 1;

	    for (int i = 1; i <= t; ++i) {
	    	int n = in.nextInt();
	    	int m = in.nextInt();
	    	int[][] uv = in.nextPairs(m);
	    	int[] u = uv[0];
	    	int[] v = uv[1];

	    	if(isDebug){
		    	out.printf("Test %d\n", i);
	    	}

			long ans = solve(u, v, n);
			out.println(ans);

			if(isDebug)
				out.flush();
	    }

	    in.close();
	    out.close();
	}

	private long solve(int[] u, int[] v, int n) {
		int m = u.length;
		// S = [0, 10^n]
		// find # of equivalance classes S/~
		// base: swap uj and vj if they are adjacent digits

		// 10^n
		// (0, 1)

		// num[i] = # nums ending in i
		long[] num = new long[10];
		for(int i=0; i<10; i++)
			num[i] = 1;

		// multipliers[i][j] = contributions from num[i] when j is appended
		long[][] multipliers = new long[10][10];
		for(int i=0; i<10; i++) {
			for(int j=0; j<10; j++) {
				multipliers[i][j] = 1;
			}
		}

		for(int i=0; i<m; i++) {
			multipliers[u[i]][v[i]] = inverse(2, MOD);
			multipliers[v[i]][u[i]] = inverse(2, MOD);
		}

		// xxxx0 + 1 -> xxxx01 * (1/2) + xxxx10 * (1/2)
		// yyyy1

		// (1/2) + (1/2) = 1
		// 2* + 2* = 1

		int temp  =1;

		for(int i=1; i<n; i++) {
			long[] num2 = new long[10];
			for(int j=0; j<10; j++) {
				for(int k=0; k<10; k++) {
					num2[j] += num[k]*multipliers[j][k] % MOD;
				}
				num2[j] %= MOD;
			}
			num = num2;
		}

		long sum = 0;
		for(int i=0; i<10; i++)
			sum += num[i];

		return sum%MOD;
	}

	static long pow(int a, int k, long p) {
		long m = k;
		long ans = 1;

		// curr = k^(2^i)
		long curr = a;

		// k^(2x+1) = (k^x)^2 * k
		while(m > 0) {
			if( (m&1) == 1 ) {
				ans *= curr;
				ans %= p;
			}
			m >>= 1;
			curr *= curr;
			curr %= p;
		}
		return ans;
	}

	// computes a^(p-2)
	static long inverse(int a, long p) {
		return pow(a, (int)(p-2), p);
	}

	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

		// 32768?
		public MyScanner(InputStream is, int bufferSize) {
			br = new BufferedReader(new InputStreamReader(is), bufferSize);
		}

		public MyScanner(InputStream is) {
			br = new BufferedReader(new InputStreamReader(is));
			// br = new BufferedReader(new InputStreamReader(System.in));
			// br = new BufferedReader(new InputStreamReader(new FileInputStream("input.txt")));
		}

		public void close() {
			try {
				br.close();
			} catch (IOException e) {
				e.printStackTrace();
			}

		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

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

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

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

		String nextLine(){
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}

		int[][] nextTreeEdges(int n, int offset){
			int[][] e = new int[n-1][2];
			for(int i=0; i<n-1; i++){
				e[i][0] = nextInt()+offset;
				e[i][1] = nextInt()+offset;
			}
			return e;
		}

		int[][] nextMatrix(int n, int m) {
			return nextMatrix(n, m, 0);
		}

		int[][] nextMatrix(int n, int m, int offset) {
			int[][] mat = new int[n][m];
			for(int i=0; i<n; i++) {
				for(int j=0; j<m; j++) {
					mat[i][j] = nextInt()+offset;
				}
			}
			return mat;
		}

		int[][] nextPairs(int n){
			return nextPairs(n, 0);
		}

		int[][] nextPairs(int n, int offset) {
			int[][] xy = new int[2][n];
			for(int i=0; i<n; i++) {
				xy[0][i] = nextInt() + offset;
				xy[1][i] = nextInt() + offset;
			}
			return xy;
		}

		int[][] nextGraphEdges(){
			return nextGraphEdges(0);
		}

		int[][] nextGraphEdges(int offset) {
			int m = nextInt();
			int[][] e = new int[m][2];
			for(int i=0; i<m; i++){
				e[i][0] = nextInt()+offset;
				e[i][1] = nextInt()+offset;
			}
			return e;
		}

		int[] nextIntArray(int len) {
			return nextIntArray(len, 0);
		}
		int[] nextIntArray(int len, int offset){
	    	int[] a = new int[len];
			for(int j=0; j<len; j++)
	    		a[j] = nextInt()+offset;
	    	return a;
		}

		long[] nextLongArray(int len) {
			return nextLongArray(len, 0);
		}
		long[] nextLongArray(int len, int offset){
	    	long[] a = new long[len];
			for(int j=0; j<len; j++)
	    		a[j] = nextLong()+offset;
	    	return a;
		}
	}

	public static class MyPrintWriter extends PrintWriter{
		public MyPrintWriter(OutputStream os) {
			super(os);
		}

		public void printlnAns(boolean ans) {
			if(ans)
				println(YES);
			else
				println(NO);
		}

		public void printAns(long[] arr){
			if(arr != null && arr.length > 0){
				print(arr[0]);
				for(int i=1; i<arr.length; i++){
					print(" ");
					print(arr[i]);
				}
			}
		}
		public void printlnAns(long[] arr){
			printAns(arr);
			println();
		}

		public void printAns(int[] arr){
			if(arr != null && arr.length > 0){
				print(arr[0]);
				for(int i=1; i<arr.length; i++){
					print(" ");
					print(arr[i]);
				}
			}
		}
		public void printlnAns(int[] arr){
			printAns(arr);
			println();
		}

		public <T> void printAns(ArrayList<T> arr){
			if(arr != null && arr.size() > 0){
				print(arr.get(0));
				for(int i=1; i<arr.size(); i++){
					print(" ");
					print(arr.get(i));
				}
			}
		}
		public <T> void printlnAns(ArrayList<T> arr){
			printAns(arr);
			println();
		}

		public void printAns(int[] arr, int add){
			if(arr != null && arr.length > 0){
				print(arr[0]+add);
				for(int i=1; i<arr.length; i++){
					print(" ");
					print(arr[i]+add);
				}
			}
		}
		public void printlnAns(int[] arr, int add){
			printAns(arr, add);
			println();
		}

		public void printAns(ArrayList<Integer> arr, int add) {
			if(arr != null && arr.size() > 0){
				print(arr.get(0)+add);
				for(int i=1; i<arr.size(); i++){
					print(" ");
					print(arr.get(i)+add);
				}
			}
		}

		public void printlnAns(ArrayList<Integer> arr, int add){
			printAns(arr, add);
			println();
		}

		public void printlnAnsSplit(long[] arr, int split){
			if(arr != null){
				for(int i=0; i<arr.length; i+=split){
					print(arr[i]);
					for(int j=i+1; j<i+split; j++){
						print(" ");
						print(arr[j]);
					}
					println();
				}
			}
		}

		public void printlnAnsSplit(int[] arr, int split){
			if(arr != null){
				for(int i=0; i<arr.length; i+=split){
					print(arr[i]);
					for(int j=i+1; j<i+split; j++){
						print(" ");
						print(arr[j]);
					}
					println();
				}
			}
		}

		public <T> void printlnAnsSplit(ArrayList<T> arr, int split){
			if(arr != null && !arr.isEmpty()){
				for(int i=0; i<arr.size(); i+=split){
					print(arr.get(i));
					for(int j=i+1; j<i+split; j++){
						print(" ");
						print(arr.get(j));
					}
					println();
				}
			}
		}
	}

	static private void permutateAndSort(int[] a) {
		int n = a.length;
		Random R = new Random(System.currentTimeMillis());
		for(int i=0; i<n; i++) {
			int t = R.nextInt(n-i);
			int temp = a[n-1-i];
			a[n-1-i] = a[t];
			a[t] = temp;
		}
		Arrays.sort(a);
	}

	static private int[][] constructChildren(int n, int[] parent, int parentRoot){
		int[][] childrens = new int[n][];

		int[] numChildren = new int[n];
		for(int i=0; i<parent.length; i++) {
			if(parent[i] != parentRoot)
				numChildren[parent[i]]++;
		}

		for(int i=0; i<n; i++) {
			childrens[i] = new int[numChildren[i]];
		}

		int[] idx = new int[n];
		for(int i=0; i<parent.length; i++) {
			if(parent[i] != parentRoot)
				childrens[parent[i]][idx[parent[i]]++] = i;
		}

		return childrens;
	}

	static private int[][][] constructDirectedNeighborhood(int n, int[][] e){
		int[] inDegree = new int[n];
		int[] outDegree = new int[n];
		for(int i=0; i<e.length; i++) {
			int u = e[i][0];
			int v = e[i][1];
			outDegree[u]++;
			inDegree[v]++;
		}

		int[][] inNeighbors = new int[n][];
		int[][] outNeighbors = new int[n][];
		for(int i=0; i<n; i++) {
			inNeighbors[i] = new int[inDegree[i]];
			outNeighbors[i] = new int[outDegree[i]];
		}

		int[] inIdx = new int[n];
		int[] outIdx = new int[n];
		for(int i=0; i<e.length; i++) {
			int u = e[i][0];
			int v = e[i][1];
			outNeighbors[u][outIdx[u]++] = v;
			inNeighbors[v][inIdx[v]++] = u;
		}

		return new int[][][] {inNeighbors, outNeighbors};
	}

	static private int[][] constructNeighborhood(int n, int[][] e) {
		int[] degree = new int[n];
		for(int i=0; i<e.length; i++) {
			int u = e[i][0];
			int v = e[i][1];
			degree[u]++;
			degree[v]++;
		}

		int[][] neighbors = new int[n][];
		for(int i=0; i<n; i++)
			neighbors[i] = new int[degree[i]];

		int[] idx = new int[n];
		for(int i=0; i<e.length; i++) {
			int u = e[i][0];
			int v = e[i][1];
			neighbors[u][idx[u]++] = v;
			neighbors[v][idx[v]++] = u;
		}

		return neighbors;
	}

	static private void makeDotUndirected(int[][] e) {
		MyPrintWriter out2 = null;
		 try {
			out2 = new MyPrintWriter(new FileOutputStream("graph.dot"));
		} catch (FileNotFoundException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		out2.println("strict graph {");
		for(int i=0; i<e.length; i++){
			out2.println(e[i][0] + "--" + e[i][1] + ";");
		}
		out2.println("}");
		out2.close();
	}

	static private void makeDotDirected(int[][] e) {
		MyPrintWriter out2 = null;
		 try {
			out2 = new MyPrintWriter(new FileOutputStream("graph.dot"));
		} catch (FileNotFoundException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		out2.println("strict digraph {");
		for(int i=0; i<e.length; i++){
			out2.println(e[i][0] + "->" + e[i][1] + ";");
		}
		out2.println("}");
		out2.close();
	}

}


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

// you can compare with output.txt and expected out
public class Round791F {
	MyPrintWriter out;
	MyScanner in;

//	final static long FIXED_RANDOM;
//	static {
//		FIXED_RANDOM = System.currentTimeMillis();
//	}
	final static String IMPOSSIBLE = "IMPOSSIBLE";
	final static String POSSIBLE = "POSSIBLE";
	final static String YES = "YES";
	final static String NO = "NO";
	final static long MOD = 998244353;

    private void initIO(boolean isFileIO) {
        if (System.getProperty("ONLINE_JUDGE") == null && isFileIO) {
        	try{
	            in = new MyScanner(new FileInputStream("input.txt"));
	            out = new MyPrintWriter(new FileOutputStream("output.txt"));
        	}
        	catch(FileNotFoundException e){
        		e.printStackTrace();
        	}
        }
        else{
    		in = new MyScanner(System.in);
    	    out = new MyPrintWriter(new BufferedOutputStream(System.out));
        }
    }

	public static void main(String[] args){
//		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));

		Round791F sol = new Round791F();
		sol.run();
    }

	private void run() {
		boolean isDebug = false;
		boolean isFileIO = true;
		boolean hasMultipleTests = false;

		initIO(isFileIO);

		int t = hasMultipleTests? in.nextInt() : 1;

	    for (int i = 1; i <= t; ++i) {
	    	int n = in.nextInt();
	    	int m = in.nextInt();
	    	int[][] uv = in.nextPairs(m);
	    	int[] u = uv[0];
	    	int[] v = uv[1];

	    	if(isDebug){
		    	out.printf("Test %d\n", i);
	    	}

			long ans = solve2(u, v, n);
			out.println(ans);

			//validate(u, v, n);

			if(isDebug)
				out.flush();
	    }

	    in.close();
	    out.close();
	}

	// wrong idea for the validator.. meh
	private void validate(int[] u, int[] v, int n) {
		TreeSet<String> set = new TreeSet<>();
		int[][] cmp = new int[RADIX][RADIX];
		for(int i=0; i<RADIX; i++) {
			for(int j=0; j<RADIX; j++) {
				cmp[i][j] = 0;
			}
		}
		for(int i=0; i<u.length; i++) {
			int small = Math.min(u[i], v[i]);
			int large = Math.max(u[i], v[i]);
			cmp[small][large] = -1;
			cmp[large][small] = 1;
		}
//		for(int i=0; i<RADIX; i++) {
//			for(int j=0; j<RADIX; j++) {
//				for(int k=0; k<RADIX; k++) {
//					if(cmp[i][j] == 1 && cmp[j][k] == 1)
//						cmp[i][k] = 1;
//					else if(cmp[i][j] == -1 && cmp[j][k] == -1)
//						cmp[i][k] = -1;
//				}
//			}
//		}

		Comparator<Character> comp = new Comparator<Character>() {
			@Override
			public int compare(Character o1, Character o2) {
				return cmp[o1-'0'][o2-'0'];
			}
		};

		BigInteger curr = BigInteger.ZERO;
		BigInteger limit = BigInteger.valueOf(RADIX).pow(n);
		StringBuilder sb = new StringBuilder();
		while(curr.compareTo(limit) < 0) {
			String s = curr.toString(RADIX);
			int padding = n-s.length();
			sb.setLength(0);
			for(int i=0; i<padding; i++)
				sb.append('0');
			sb.append(s);
			Character[] arr = new Character[n];
			for(int i=0; i<n; i++)
				arr[i] = sb.charAt(i);
			 Arrays.sort(arr, comp);
			// can't use sorting since comp is not transitive
			// actually, should make transitive

//			char[] arr = new char[n];
//			for(int i=0; i<n; i++)
//				arr[i] = sb.charAt(i);
//
//			for(int i=n-1; i>=0; i--) {
//				for(int j=0; j<i; j++) {
//					if(cmp[arr[j]-'0'][arr[j+1]-'0'] == 1) {
//						char temp = arr[j+1];
//						arr[j+1] = arr[j];
//						arr[j] = temp;
//					}
//				}
//			}

			sb.setLength(0);
//			sb.append(arr);
			for(int i=0; i<n; i++)
				sb.append(arr[i]);
			set.add(sb.toString());
			curr = curr.add(BigInteger.ONE);
		}
		out.println(set.size());
		out.println(set);

		// 4 3
		// 0 1
		// 0 2
		// 2 3

		// 0302 -> 0320 -> 0230

        // [0000, 0001, 0002, 0003, 0011, 0012, 0013, 0021, 0022, 0023, 0030, 0031, 0033,
		// 0111, 0112, 0113, 0121, 0122, 0123, 0130, 0131, 0133,
		// 0211, 0212, 0213, 0221, 0222, 0223, 0230, 0231, 0233,
		// 0300, 0301, 0302, 0303, 0311, 0312, 0313, 0330, 0331, 0333,
		// 1111, 1112, 1113, 1121, 1122, 1123, 1130, 1131, 1133, 1211,
		// 1212, 1213, 1221, 1222, 1223, 1230, 1231, 1233,
		// 1300, 1301, 1302, 1303, 1311, 1312, 1313, 1330, 1331, 1333,
		// 2111, 2112, 2113, 2121, 2122, 2123, 2130, 2131, 2133,
		// 2211, 2212, 2213, 2221, 2222, 2223, 2230, 2231, 2233,
		// 2300, 2301, 2302, 2303, 2311, 2312, 2313, 2330, 2331, 2333,
		// 3000, 3001, 3002, 3003, 3011, 3012, 3013, 3021, 3022, 3023, 3030, 3031, 3033,
		// 3111, 3112, 3113, 3121, 3122, 3123, 3130, 3131, 3133,
		// 3300, 3301, 3302, 3303, 3311, 3312, 3313, 3330, 3331, 3333]

		// when inserting j
		// X +
	}

	final int RADIX = 10;
	private long solve2(int[] u, int[] v, int n) {
		// dp[i][set] = a[n-i..n-1] where elements in the set can move forward
		long[][] dp = new long[n][1<<RADIX];

		for(int j=0; j<RADIX; j++) {
			dp[n-1][1<<j] = 1;
		}

		int[][] cmp = new int[RADIX][RADIX];
		int m = u.length;
		for(int i=0; i<m; i++) {
			int small = Math.min(u[i], v[i]);
			int larger = Math.max(u[i], v[i]);
			cmp[small][larger] = -1;
			cmp[larger][small] = 1;
		}

		boolean[][] isValid = new boolean[1<<RADIX][RADIX];
		int[][] map = new int[1<<RADIX][RADIX];

		for(int mask=0; mask< 1<<RADIX; mask++) {
			for(int j=0; j<RADIX; j++) {
				boolean ok = true;
				int next = 1<<j;
				for(int k=0; k<RADIX; k++) {
					if( (1<<k & mask) == 0)
						continue;
					// k can come forward
					// case 1: j is incomparable to k
					// -> remove k from the set
					if(cmp[j][k] == 0) {
					}
					// case 2: j, k can be swapped and j is smaller
					else if(cmp[j][k] == -1) {
						next |= 1<<k;
					}
					// case 3: j, k can be swapped and j is larger -> not a representative
					else {
						ok = false;
					}
				}
				isValid[mask][j] = ok;
				map[mask][j] = next;
			}
		}

		// n*2^RADIX*RADIX = 5*10^4*10^3*10 = 5*10^8
		for(int i=n-2; i>=0; i--) {
			for(int mask=0; mask < 1<<RADIX; mask++) {
				for(int j=0; j<RADIX; j++) {
					if(!isValid[mask][j])
						continue;
					int mask2 = map[mask][j];
					long val = dp[i][mask2] + dp[i+1][mask];
					dp[i][mask2] = val < MOD? val: val-MOD;
				}
			}
		}

		long sum = 0;
		for(int mask=0; mask < 1<<RADIX; mask++)
			sum += dp[0][mask]; // < Integer.MAX_VALUE * 10^3
		return sum%MOD;
	}

	private long solve(int[] u, int[] v, int n) {
		int m = u.length;
		// S = [0, 10^n]
		// find # of equivalance classes S/~
		// base: swap uj and vj if they are adjacent digits

		// 10^n
		// (0, 1)

		// num[i] = # nums ending in i
		long[] num = new long[RADIX];
		for(int i=0; i<RADIX; i++)
			num[i] = 1;

		// multipliers[i][j] = contributions from num[i] when j is appended
		long[][] multipliers = new long[RADIX][RADIX];
		for(int i=0; i<RADIX; i++) {
			for(int j=0; j<RADIX; j++) {
				multipliers[i][j] = 1;
			}
		}

		for(int i=0; i<m; i++) {
			int min = Math.min(u[i], v[i]);
			int max = Math.max(u[i], v[i]);
			multipliers[max][min] = 0;
		}

		// xxxx0 + 1 -> xxxx01 * (1/2) + xxxx10 * (1/2)
		// yyyy1

		// (1/2) + (1/2) = 1
		// 2* + 2* = 1

		// string made of (0, 1)
		// -> different iff it has diff # of 0 or diff # of 1

		// (0, 1) (1, 2)
		// 0000000022222222
		// 0 and 2 can't swap
		// 021

		// xxxx0 + 0 -> k
		// xxxx0 + 1 -> k

		// xxxx1 + 0 -> X
		//

		int temp  =1;

		for(int i=1; i<n; i++) {
			long[] num2 = new long[RADIX];
			for(int j=0; j<RADIX; j++) {
				for(int k=0; k<RADIX; k++) {
					num2[j] += num[k]*multipliers[j][k] % MOD;
				}
				num2[j] %= MOD;
			}
			num = num2;
		}

		long sum = 0;
		for(int i=0; i<RADIX; i++)
			sum += num[i];

		return sum%MOD;
	}

	static long pow(int a, int k, long p) {
		long m = k;
		long ans = 1;

		// curr = k^(2^i)
		long curr = a;

		// k^(2x+1) = (k^x)^2 * k
		while(m > 0) {
			if( (m&1) == 1 ) {
				ans *= curr;
				ans %= p;
			}
			m >>= 1;
			curr *= curr;
			curr %= p;
		}
		return ans;
	}

	// computes a^(p-2)
	static long inverse(int a, long p) {
		return pow(a, (int)(p-2), p);
	}

	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

		// 32768?
		public MyScanner(InputStream is, int bufferSize) {
			br = new BufferedReader(new InputStreamReader(is), bufferSize);
		}

		public MyScanner(InputStream is) {
			br = new BufferedReader(new InputStreamReader(is));
			// br = new BufferedReader(new InputStreamReader(System.in));
			// br = new BufferedReader(new InputStreamReader(new FileInputStream("input.txt")));
		}

		public void close() {
			try {
				br.close();
			} catch (IOException e) {
				e.printStackTrace();
			}

		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

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

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

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

		String nextLine(){
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}

		int[][] nextTreeEdges(int n, int offset){
			int[][] e = new int[n-1][2];
			for(int i=0; i<n-1; i++){
				e[i][0] = nextInt()+offset;
				e[i][1] = nextInt()+offset;
			}
			return e;
		}

		int[][] nextMatrix(int n, int m) {
			return nextMatrix(n, m, 0);
		}

		int[][] nextMatrix(int n, int m, int offset) {
			int[][] mat = new int[n][m];
			for(int i=0; i<n; i++) {
				for(int j=0; j<m; j++) {
					mat[i][j] = nextInt()+offset;
				}
			}
			return mat;
		}

		int[][] nextPairs(int n){
			return nextPairs(n, 0);
		}

		int[][] nextPairs(int n, int offset) {
			int[][] xy = new int[2][n];
			for(int i=0; i<n; i++) {
				xy[0][i] = nextInt() + offset;
				xy[1][i] = nextInt() + offset;
			}
			return xy;
		}

		int[][] nextGraphEdges(){
			return nextGraphEdges(0);
		}

		int[][] nextGraphEdges(int offset) {
			int m = nextInt();
			int[][] e = new int[m][2];
			for(int i=0; i<m; i++){
				e[i][0] = nextInt()+offset;
				e[i][1] = nextInt()+offset;
			}
			return e;
		}

		int[] nextIntArray(int len) {
			return nextIntArray(len, 0);
		}
		int[] nextIntArray(int len, int offset){
	    	int[] a = new int[len];
			for(int j=0; j<len; j++)
	    		a[j] = nextInt()+offset;
	    	return a;
		}

		long[] nextLongArray(int len) {
			return nextLongArray(len, 0);
		}
		long[] nextLongArray(int len, int offset){
	    	long[] a = new long[len];
			for(int j=0; j<len; j++)
	    		a[j] = nextLong()+offset;
	    	return a;
		}
	}

	public static class MyPrintWriter extends PrintWriter{
		public MyPrintWriter(OutputStream os) {
			super(os);
		}

		public void printlnAns(boolean ans) {
			if(ans)
				println(YES);
			else
				println(NO);
		}

		public void printAns(long[] arr){
			if(arr != null && arr.length > 0){
				print(arr[0]);
				for(int i=1; i<arr.length; i++){
					print(" ");
					print(arr[i]);
				}
			}
		}
		public void printlnAns(long[] arr){
			printAns(arr);
			println();
		}

		public void printAns(int[] arr){
			if(arr != null && arr.length > 0){
				print(arr[0]);
				for(int i=1; i<arr.length; i++){
					print(" ");
					print(arr[i]);
				}
			}
		}
		public void printlnAns(int[] arr){
			printAns(arr);
			println();
		}

		public <T> void printAns(ArrayList<T> arr){
			if(arr != null && arr.size() > 0){
				print(arr.get(0));
				for(int i=1; i<arr.size(); i++){
					print(" ");
					print(arr.get(i));
				}
			}
		}
		public <T> void printlnAns(ArrayList<T> arr){
			printAns(arr);
			println();
		}

		public void printAns(int[] arr, int add){
			if(arr != null && arr.length > 0){
				print(arr[0]+add);
				for(int i=1; i<arr.length; i++){
					print(" ");
					print(arr[i]+add);
				}
			}
		}
		public void printlnAns(int[] arr, int add){
			printAns(arr, add);
			println();
		}

		public void printAns(ArrayList<Integer> arr, int add) {
			if(arr != null && arr.size() > 0){
				print(arr.get(0)+add);
				for(int i=1; i<arr.size(); i++){
					print(" ");
					print(arr.get(i)+add);
				}
			}
		}

		public void printlnAns(ArrayList<Integer> arr, int add){
			printAns(arr, add);
			println();
		}

		public void printlnAnsSplit(long[] arr, int split){
			if(arr != null){
				for(int i=0; i<arr.length; i+=split){
					print(arr[i]);
					for(int j=i+1; j<i+split; j++){
						print(" ");
						print(arr[j]);
					}
					println();
				}
			}
		}

		public void printlnAnsSplit(int[] arr, int split){
			if(arr != null){
				for(int i=0; i<arr.length; i+=split){
					print(arr[i]);
					for(int j=i+1; j<i+split; j++){
						print(" ");
						print(arr[j]);
					}
					println();
				}
			}
		}

		public <T> void printlnAnsSplit(ArrayList<T> arr, int split){
			if(arr != null && !arr.isEmpty()){
				for(int i=0; i<arr.size(); i+=split){
					print(arr.get(i));
					for(int j=i+1; j<i+split; j++){
						print(" ");
						print(arr.get(j));
					}
					println();
				}
			}
		}
	}

	static private void permutateAndSort(int[] a) {
		int n = a.length;
		Random R = new Random(System.currentTimeMillis());
		for(int i=0; i<n; i++) {
			int t = R.nextInt(n-i);
			int temp = a[n-1-i];
			a[n-1-i] = a[t];
			a[t] = temp;
		}
		Arrays.sort(a);
	}

	static private int[][] constructChildren(int n, int[] parent, int parentRoot){
		int[][] childrens = new int[n][];

		int[] numChildren = new int[n];
		for(int i=0; i<parent.length; i++) {
			if(parent[i] != parentRoot)
				numChildren[parent[i]]++;
		}

		for(int i=0; i<n; i++) {
			childrens[i] = new int[numChildren[i]];
		}

		int[] idx = new int[n];
		for(int i=0; i<parent.length; i++) {
			if(parent[i] != parentRoot)
				childrens[parent[i]][idx[parent[i]]++] = i;
		}

		return childrens;
	}

	static private int[][][] constructDirectedNeighborhood(int n, int[][] e){
		int[] inDegree = new int[n];
		int[] outDegree = new int[n];
		for(int i=0; i<e.length; i++) {
			int u = e[i][0];
			int v = e[i][1];
			outDegree[u]++;
			inDegree[v]++;
		}

		int[][] inNeighbors = new int[n][];
		int[][] outNeighbors = new int[n][];
		for(int i=0; i<n; i++) {
			inNeighbors[i] = new int[inDegree[i]];
			outNeighbors[i] = new int[outDegree[i]];
		}

		int[] inIdx = new int[n];
		int[] outIdx = new int[n];
		for(int i=0; i<e.length; i++) {
			int u = e[i][0];
			int v = e[i][1];
			outNeighbors[u][outIdx[u]++] = v;
			inNeighbors[v][inIdx[v]++] = u;
		}

		return new int[][][] {inNeighbors, outNeighbors};
	}

	static private int[][] constructNeighborhood(int n, int[][] e) {
		int[] degree = new int[n];
		for(int i=0; i<e.length; i++) {
			int u = e[i][0];
			int v = e[i][1];
			degree[u]++;
			degree[v]++;
		}

		int[][] neighbors = new int[n][];
		for(int i=0; i<n; i++)
			neighbors[i] = new int[degree[i]];

		int[] idx = new int[n];
		for(int i=0; i<e.length; i++) {
			int u = e[i][0];
			int v = e[i][1];
			neighbors[u][idx[u]++] = v;
			neighbors[v][idx[v]++] = u;
		}

		return neighbors;
	}

	static private void makeDotUndirected(int[][] e) {
		MyPrintWriter out2 = null;
		 try {
			out2 = new MyPrintWriter(new FileOutputStream("graph.dot"));
		} catch (FileNotFoundException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		out2.println("strict graph {");
		for(int i=0; i<e.length; i++){
			out2.println(e[i][0] + "--" + e[i][1] + ";");
		}
		out2.println("}");
		out2.close();
	}

	static private void makeDotDirected(int[][] e) {
		MyPrintWriter out2 = null;
		 try {
			out2 = new MyPrintWriter(new FileOutputStream("graph.dot"));
		} catch (FileNotFoundException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		out2.println("strict digraph {");
		for(int i=0; i<e.length; i++){
			out2.println(e[i][0] + "->" + e[i][1] + ";");
		}
		out2.println("}");
		out2.close();
	}

}


import static java.lang.Math.max;
import static java.lang.Math.min;
import static java.lang.Math.abs;
import static java.lang.System.out;
import java.util.*;
import java.io.*;
import java.math.*;

public class HelloWorld{

     public static void main(String []args) throws Exception
     {
        BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(infile.readLine());
        int n =Integer.parseInt(st.nextToken());
        long mod =Long.parseLong(st.nextToken());
        long[] dp=new long[n+1];
        long ans=1+n-(n+1)/2;
        if(n%2==1) ans++;
        dp[n]=1;
        long[] prefix=new long[n*1000];
        prefix[n]=1;
        for(int i=n-1;i>=1;i--){
            dp[i]=prefix[i+1];
            for(int j=2;j*i<=n;j++){
                 dp[i]=(dp[i]+prefix[j*i]-prefix[j*(i+1)])%mod;
            }
            prefix[i]=(prefix[i+1]+dp[i])%mod;
        }
         System.out.println(dp[1]);
     }
}


import java.util.*;

import javax.xml.crypto.dsig.spec.DigestMethodParameterSpec;

import org.omg.CORBA.PUBLIC_MEMBER;

import java.io.*;
import java.math.*;
import java.awt.geom.*;

import static java.lang.Math.*;

public class Solution implements Runnable {

	long mod1 = (long) 1e9 + 7;
	int mod2 = 998244353;

	public void solve() throws Exception {
			int n=sc.nextInt(); long mod=sc.nextLong();
			long dp[] = new long[n+1];
			out.println(ans(n, mod, dp));
	}

	public long ans(int n, long mod, long dp[]) {
		if(n==1) return 1;
		long res=0;
		if(dp[n]!=0) return dp[n];
		for(int i=1;i<n;i++) {
			res=(res+ans(n-i, mod, dp))%mod;
		}
		for(int i=2;i<=n;i++) {
			res=(res+ans(n/i, mod, dp))%mod;
		}
		return dp[n]=(res+mod)%mod;
	}

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

	static void sort(int[] a) {
		ArrayList<Integer> l = new ArrayList<>();
		for (int i : a)
			l.add(i);
		Collections.sort(l);
		for (int i = 0; i < a.length; i++)
			a[i] = l.get(i);
	}

	static long ncr(int n, int r, long p) {
		if (r > n)
			return 0l;
		if (r > n - r)
			r = n - r;

		long C[] = new long[r + 1];

		C[0] = 1;

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

			for (int j = Math.min(i, r); j > 0; j--)
				C[j] = (C[j] + C[j - 1]) % p;
		}
		return C[r] % p;
	}

	void sieveOfEratosthenes(boolean prime[], int size) {
		for (int i = 0; i < size; i++)
			prime[i] = true;

		for (int p = 2; p * p < size; p++) {
			if (prime[p] == true) {
				for (int i = p * p; i < size; i += p)
					prime[i] = false;
			}
		}
	}

	static int LowerBound(int a[], int x) { // smallest index having value >= x
		int l = -1, r = a.length;
		while (l + 1 < r) {
			int m = (l + r) >>> 1;
			if (a[m] >= x)
				r = m;
			else
				l = m;
		}
		return r;
	}

	static int UpperBound(int a[], int x) {// biggest index having value <= x
		int l = -1, r = a.length;
		while (l + 1 < r) {
			int m = (l + r) >>> 1;
			if (a[m] <= x)
				l = m;
			else
				r = m;
		}
		return l + 1;
	}

	public long power(long x, long y, long p) {
		long res = 1;
		// out.println(x+" "+y);
		x = x % p;
		if (x == 0)
			return 0;

		while (y > 0) {
			if ((y & 1) == 1)
				res = (res * x) % p;
			y = y >> 1;
			x = (x * x) % p;
		}
		return res;
	}

	static Throwable uncaught;

	BufferedReader in;
	FastScanner sc;
	PrintWriter out;

	@Override
	public void run() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
			sc = new FastScanner(in);
			solve();
		} catch (Throwable uncaught) {
			Solution.uncaught = uncaught;
		} finally {
			out.close();
		}
	}

	public static void main(String[] args) throws Throwable {
		Thread thread = new Thread(null, new Solution(), "", (1 << 26));
		thread.start();
		thread.join();
		if (Solution.uncaught != null) {
			throw Solution.uncaught;
		}
	}

}

class FastScanner {

	BufferedReader in;
	StringTokenizer st;

	public FastScanner(BufferedReader in) {
		this.in = in;
	}

	public String nextToken() throws Exception {
		while (st == null || !st.hasMoreTokens()) {
			st = new StringTokenizer(in.readLine());
		}
		return st.nextToken();
	}

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

	public int[] readArray(int n) throws Exception {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = nextInt();
		return a;
	}

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

	public double nextDouble() throws Exception {
		return Double.parseDouble(nextToken());
	}

}


import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.util.Arrays;
import java.util.Scanner;

public class CF_Edu_108_F {
	static boolean verb=true;
	static void log(Object X){if (verb) System.err.println(X);}
	static void log(Object[] X){if (verb) {for (Object U:X) System.err.print(U+" ");System.err.println("");}}
	static void log(int[] X){if (verb) {for (int U:X) System.err.print(U+" ");System.err.println("");}}
	static void log(int[] X,int L){if (verb) {for (int i=0;i<L;i++) System.err.print(X[i]+" ");System.err.println("");}}
	static void log(long[] X){if (verb) {for (long U:X) System.err.print(U+" ");System.err.println("");}}

	static InputReader reader;

	static class Composite {
		int msk;
		int cost;

		Composite left;
		Composite right;

	}

	public static void main(String[] args) throws Exception  {

		log(1<<6);
		reader=new InputReader(System.in);
		int n=reader.readInt();
		int m=reader.readInt();
		int[] a=new int[n];
		int tot=0;
		for (int i=0;i<n;i++) {
			a[i]=reader.readInt();
			tot+=a[i];
		}
		int[] b=new int[m];
		for (int i=0;i<m;i++)
			b[i]=reader.readInt();

		int[][] c=new int[n][m];
		for (int i=0;i<n;i++)
			for (int j=0;j<m;j++)
				c[i][j]=reader.readInt();

		int MX=1<<m;

		int[][] cost=new int[n][MX];
		int[] bill=new int[MX];

		for (int w=0;w<MX;w++)
			for (int j=0;j<m;j++)
				if (((1<<j)&w)!=0) {
					bill[w]+=b[j];
					for (int i=0;i<n;i++)
						cost[i][w]+=c[i][j];
				}

		int FX=Integer.MAX_VALUE;
		int VX=m*4+1;
		int[][] spend=new int[MX][VX];

		for (int w=0;w<MX;w++) {
			Arrays.fill(spend[w], FX);
			if (bill[w]>=a[0]) {
				// ok for me
				// now we look at the previous
				spend[w][bill[w]-a[0]]=cost[0][w];
				//log("adding:"+w);
			}
		}

		for (int i=1;i<n;i++) {
			int[][] nxt=new int[MX][VX];
			for (int w=0;w<MX;w++)
				Arrays.fill(nxt[w],FX);
			for (int w=0;w<MX;w++) {
				if (bill[w]>=a[i]) {
					//log("considering:"+w);
					// ok for me
					// now we look at the previous
					for (int u=0;u<MX;u++)
						for (int v=0;v<VX;v++) {
							if (spend[u][v]<FX) {
								//log("----interested by u:"+u);
								int nu=u|w;
								int nv=v+bill[w]-bill[w&u]-a[i];
								//log("nv:"+nv);
								if (nv>=0) {
									//log("----merging");
									nxt[nu][nv]=Math.min(spend[u][v]+cost[i][w], nxt[nu][nv]);
								}
							}
						}
				}

			}
			spend=nxt;
		}
		int ans=FX;
		for (int w=0;w<MX;w++)
			for (int v=0;v<VX;v++)
				ans=Math.min(ans, spend[w][v]);

		if (ans==FX)
			ans=-1;
		System.out.println(ans);

}

static final class InputReader {
	private final InputStream stream;
	private final byte[] buf = new byte[1024];
	private int curChar;
	private int numChars;

	public InputReader(InputStream stream) {
		this.stream = stream;
	}

	private int read() throws IOException {
		if (curChar >= numChars) {
			curChar = 0;
			numChars = stream.read(buf);
			if (numChars <= 0) {
				return -1;
			}
		}
		return buf[curChar++];
	}

	public final String readString() throws IOException {
		int c = read();
		while (isSpaceChar(c)) {
			c = read();
		}
		StringBuilder res=new StringBuilder();
		do {
			res.append((char)c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

	public final int readInt() throws IOException {
		int c = read();
		boolean neg=false;
		while (isSpaceChar(c)) {
			c = read();
		}
		char d=(char)c;
		//log("d:"+d);
		if (d=='-') {
			neg=true;
			c = read();
		}
		int res = 0;
		do {
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		//log("res:"+res);
		if (neg)
			return -res;
		return res;

	}

	public final long readLong() throws IOException {
		int c = read();
		boolean neg=false;
		while (isSpaceChar(c)) {
			c = read();
		}
		char d=(char)c;
		//log("d:"+d);
		if (d=='-') {
			neg=true;
			c = read();
		}
		long res = 0;
		do {
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		//log("res:"+res);
		if (neg)
			return -res;
		return res;

	}

	private boolean isSpaceChar(int c) {
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}
}
}


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

public class B{

    public static int takeInt(BufferedReader br)throws IOException{
        int n=Integer.parseInt(br.readLine().trim());
        return n;
    }
    public static String[] takeStrings(BufferedReader br)throws IOException{
        String inp[]=br.readLine().trim().split(" ");
        return inp;
    }
    public static int[] takeInts(BufferedReader br)throws IOException{
        String inp[]=takeStrings(br);
        int n=inp.length;
        int arr[]=new int[n];
        for(int i=0;i<n;i++){
            arr[i]=Integer.parseInt(inp[i]);
        }
        return arr;
    }
    public static char[] generateStrings(char str[], int n, char dig){
       char strs[]=new char[n];
       for(int i=0;i<n;i++){
           if(str[i] == 'X') strs[i]=dig;
           else strs[i]=str[i];
       }
       return strs;
    }
    public static void main(String args[])throws IOException{
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        int test = 1;
        StringBuilder ans=new StringBuilder();
        outer:while(test-->0){

            char str[]=br.readLine().trim().toCharArray();
            int n=str.length;

            if(n == 1){
                if(str[0] == '0' && str[0] == '_' || str[0] == 'X' || str[0] == '1'){
                    ans.append(1+"\n");continue;
                }
            }
            long cnt=0;
            boolean Xp =false;
            // boolean allZero=true;
            // for(int i=0;i<n;i++) if(str[i] != '0') allZero=false;

            for(int i=0;i<n;i++) if(str[i] == 'X') Xp=true;

            if(Xp){
                for(char ch='0';ch<='9';ch++){
                    cnt+=solve(generateStrings(str, n, ch), n);
                }
            }
            else{
                cnt+=solve(str, n);
            }

            ans.append(cnt+"\n");
        }
        System.out.println(ans);
    }
    public static long cal(char str[], String suffix, int n, int un)
    {
        if(n<2) return 0;
        char last =suffix.charAt(1);
        char first=suffix.charAt(0);
        if(str[n-1] == '_' || str[n-1] == last){
            if(str[n-2] == '_' || str[n-2] == first ){
                return (long)Math.pow(10, un);
            }
        }

        return 0;
    }
    public static long solve(char str[], int n){
        if(n == 1 || str[0] == '0') return 0;
        long a=0,b=0,c=0,d=0;
        int un=0;
        for(int i=1;i<n-2;i++) if(str[i] == '_') ++un;
        long cnt=0;

        cnt+=cal(str, "25", n, un);
        cnt+=cal(str, "50", n, un);
        cnt+=cal(str, "75", n, un);

        if(n>2)
        if(str[0] == '_') cnt*=9l;

        // System.out.println(new String(str));

        if(n>=3)
        {
            if((str[n-1] == '_' || str[n-1] == '0') && (str[n-2] == '_' || str[n-2] == '0')){
                if(n>3)
                {
                    long temp=(long)Math.pow(10, un);
                    if(str[0] == '_') temp*=9l;
                    cnt+=temp;
                }
                else if(n == 3)
                {
                    // System.out.println("Entering...."+str[0]);
                    if(str[0] == '_'){
                        cnt+=9;
                        // System.out.println("Entered@"+cnt);
                    }
                    else{
                        cnt+=1;
                    }
                }
            }
        }

        // System.out.println(cnt);
        return cnt;
    }
}


import java.io.*;
import java.util.*;
public class Main {
    public static void main(String args[])
    {
        FastReader input=new FastReader();
        PrintWriter out=new PrintWriter(System.out);
        int T=1;
        while(T-->0)
        {
            String s=input.next();
            if(s.length()==1)
            {
                if(s.charAt(0)=='0' || s.charAt(0)=='_' || s.charAt(0)=='X') out.println(1);
                else out.println(0);
            }
            else
            {
                int f=0;
                for(int i=0;i<s.length();i++)
                {
                    if(s.charAt(i)=='X')
                    {
                        f=1;
                        break;
                    }
                }
                if(f==0)
                {
                    out.println(fun(s));
                }
                else
                {
                    int sum=0;
                    for(int i=0;i<10;i++)
                    {
                        char ch[]=s.toCharArray();
                        for(int j=0;j<s.length();j++)
                        {
                            if(ch[j]=='X')
                            {
                                ch[j]=(char)(i+'0');
                            }
                        }
                        String str=String.copyValueOf(ch);
                        sum+=fun(str);
                    }
                    out.println(sum);
                }
            }
        }
        out.close();
    }
    public static int fun(String s)
    {
        int n=s.length();
        int p=0;
        if(s.charAt(0)!='0')p=1;
        for(int i=0;i<n-2;i++)
        {
            if(s.charAt(i)=='_')
            {
                if(i==0) p*=9;
                else p*=10;
            }
        }
        int p1=0;
        if(s.charAt(n-1)=='_' && s.charAt(n-2)=='_')
        {
            p1=4;
        }
        else if(s.charAt(n-1)=='_')
        {
            if(s.charAt(n-2)=='0' || s.charAt(n-2)=='5' || s.charAt(n-2)=='2' || s.charAt(n-2)=='7') p1=1;
        }
        else if(s.charAt(n-2)=='_')
        {
            if(s.charAt(n-1)=='0') p1=2;
            else if(s.charAt(n-1)=='5') p1=2;
        }
        else
        {
            int val=Integer.valueOf(s.substring(n-2));
            if(val%25==0) p1=1;
        }
        int pro=p*p1;
        return pro;
    }
    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;
        public FastReader()
        {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        int nextInt()
        {
            return Integer.parseInt(next());
        }
        long nextLong()
        {
            return Long.parseLong(next());
        }
        double nextDouble()
        {
            return Double.parseDouble(next());
        }
        String nextLine()
        {
            String str="";
            try
            {
                str=br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}


import java.util.*;
import java.io.*;
public class Solution {

    public static Integer[][][] dp;

    public static int f(int p, int x, int lastTwoDigit, int len, String str) {
        if (p == len) {
            if (lastTwoDigit == 0 || lastTwoDigit == 25 || lastTwoDigit == 50 || lastTwoDigit == 75) {
                return 1;
            }
            return 0;
        }
        if (dp[p][x][lastTwoDigit] != null) {
            return dp[p][x][lastTwoDigit];
        }
        int ans = 0;
        if (str.charAt(p) == 'X') {
            if (x != 10) {
                ans = f(p + 1, x, (lastTwoDigit % 10) * 10 + x, len, str);
            } else {
                for (int i = (p == 0 ? 1 : 0); i < 10; i++) {
                    ans += f(p + 1, i, (lastTwoDigit % 10) * 10 + i, len, str);
                }
            }
        } else if (str.charAt(p) == '_') {
            for (int i = (p == 0 ? 1 : 0); i < 10; i++) {
                ans += f(p + 1, x, (lastTwoDigit % 10) * 10 + i, len, str);
            }
        } else {
            ans += f(p + 1, x, (lastTwoDigit % 10) * 10 + (str.charAt(p) - 48), len, str);
        }
        return dp[p][x][lastTwoDigit] = ans;
    }

    public static void solve(InputReader in, PrintWriter out) {
        String str = in.next();
        int len = str.length();
        if (len == 1) {
            if (str.charAt(0) == '0') {
                out.println(1);
            } else {
                out.println(0);
            }
        } else if (str.charAt(0) == '0') {
            out.println(0);
        } else {
            dp = new Integer[len][11][100];
            out.println(f(0, 10, 0, len, str));
        }
    }

    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        solve(in, out);
        out.close();
    }
    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());
        }

    }
}


import java.io.*;
import java.lang.Math;
import java.lang.reflect.Array;
import java.util.*;
import javax.swing.text.DefaultStyledDocument.ElementSpec;

public final class Solution {

  static BufferedReader br = new BufferedReader(
    new InputStreamReader(System.in)
  );
  static BufferedWriter bw = new BufferedWriter(
    new OutputStreamWriter(System.out)
  );
  static StringTokenizer st;

  /*write your constructor and global variables here*/

  static class sortCond implements Comparator<Pair<Integer, Integer>> {

    @Override
    public int compare(Pair<Integer, Integer> p1, Pair<Integer, Integer> p2) {
      if (p1.a <= p2.a) {
        return -1;
      } else {
        return 1;
      }
    }
  }

  static class Rec {

    int a;
    int b;
    long c;

    Rec(int a, int b, long c) {
      this.a = a;
      this.b = b;
      this.c = c;
    }
  }

  static class Pair<f, s> {

    f a;
    s b;

    Pair(f a, s b) {
      this.a = a;
      this.b = b;
    }
  }

  interface modOperations {
    int mod(int a, int b, int mod);
  }

  static int findBinaryExponentian(int a, int pow, int mod) {
    if (pow == 1) {
      return a;
    } else if (pow == 0) {
      return 1;
    } else {
      int retVal = findBinaryExponentian(a, (int) pow / 2, mod);
      int val = (pow % 2 == 0) ? 1 : a;
      return modMul.mod(modMul.mod(retVal, retVal, mod), val, mod);
    }
  }

  static int findPow(int a, int b, int mod) {
    if (b == 1) {
      return a % mod;
    } else if (b == 0) {
      return 1;
    } else {
      int res = findPow(a, (int) b / 2, mod);
      return modMul.mod(res, modMul.mod(res, (b % 2 == 1 ? a : 1), mod), mod);
    }
  }

  static int bleft(int ele, int[] sortedArr) {
    int l = 0;
    int h = sortedArr.length - 1;
    int ans = -1;
    while (l <= h) {
      int mid = l + (int) (h - l) / 2;
      if (sortedArr[mid] < ele) {
        ans = mid;
        l = mid + 1;
      } else if (sortedArr[mid] >= ele) {
        h = mid - 1;
      }
    }
    return ans;
  }

  static int gcd(int a, int b) {
    int div = b;
    int rem = a % b;
    while (rem != 0) {
      int temp = rem;
      rem = div % rem;
      div = temp;
    }
    return div;
  }

  static long[] log(long no, long n) {
    long i = 1;
    int cnt = 0;
    long sum = 0l;
    long arr[] = new long[2];
    while (i < no) {
      sum += i;
      cnt++;
      if (sum == n) {
        arr[0] = 1l * cnt;
        arr[1] = sum;
        break;
      }
      i *= 2l;
    }
    if (arr[0] == 0) {
      arr[0] = cnt;
      arr[1] = sum;
    }
    return arr;
  }

  static modOperations modAdd = (int a, int b, int mod) -> {
    return (a % mod + b % mod) % mod;
  };
  static modOperations modSub = (int a, int b, int mod) -> {
    return (int) ((1l * a % mod - 1l * b % mod + 1l * mod) % mod);
  };
  static modOperations modMul = (int a, int b, int mod) -> {
    return (int) ((1l * (a % mod) * 1l * (b % mod)) % (1l * mod));
  };
  static modOperations modDiv = (int a, int b, int mod) -> {
    return modMul.mod(a, findBinaryExponentian(b, mod - 1, mod), mod);
  };

  static HashSet<Integer> primeList(int MAXI) {
    int[] prime = new int[MAXI + 1];
    HashSet<Integer> obj = new HashSet<>();
    for (int i = 2; i <= (int) Math.sqrt(MAXI) + 1; i++) {
      if (prime[i] == 0) {
        obj.add(i);
        for (int j = i * i; j <= MAXI; j += i) {
          prime[j] = 1;
        }
      }
    }
    for (int i = (int) Math.sqrt(MAXI) + 1; i <= MAXI; i++) {
      if (prime[i] == 0) {
        obj.add(i);
      }
    }
    return obj;
  }

  static int[] factorialList(int MAXI, int mod) {
    int[] factorial = new int[MAXI + 1];
    factorial[2] = 1;
    for (int i = 3; i < MAXI + 1; i++) {
      factorial[i] = modMul.mod(factorial[i - 1], i, mod);
    }
    return factorial;
  }

  static void put(HashMap<Integer, Integer> cnt, int key) {
    if (cnt.containsKey(key)) {
      cnt.replace(key, cnt.get(key) + 1);
    } else {
      cnt.put(key, 1);
    }
  }

  static long arrSum(ArrayList<Long> arr) {
    long tot = 0;
    for (int i = 0; i < arr.size(); i++) {
      tot += arr.get(i);
    }
    return tot;
  }

  static int ord(char b) {
    return (int) b - (int) 'a';
  }

  static int optimSearch(int[] cnt, int lower_bound, int pow, int n) {
    int l = lower_bound + 1;
    int h = n;
    int ans = 0;
    while (l <= h) {
      int mid = l + (h - l) / 2;
      if (cnt[mid] - cnt[lower_bound] == pow) {
        return mid;
      } else if (cnt[mid] - cnt[lower_bound] < pow) {
        ans = mid;
        l = mid + 1;
      } else {
        h = mid - 1;
      }
    }
    return ans;
  }

  static Pair<Long, Integer> ret_ans(ArrayList<Integer> ans) {
    int size = ans.size();
    int mini = 1000000000 + 1;
    long tit = 0l;
    for (int i = 0; i < size; i++) {
      tit += 1l * ans.get(i);
      mini = Math.min(mini, ans.get(i));
    }
    return new Pair<>(tit - mini, mini);
  }

  static int factorList(
    HashMap<Integer, Integer> maps,
    int no,
    int maxK,
    int req
  ) {
    int i = 1;
    while (i * i <= no) {
      if (no % i == 0) {
        if (i != no / i) {
          put(maps, no / i);
        }
        put(maps, i);
        if (maps.get(i) == req) {
          maxK = Math.max(maxK, i);
        }
        if (maps.get(no / i) == req) {
          maxK = Math.max(maxK, no / i);
        }
      }
      i++;
    }
    return maxK;
  }

  static ArrayList<Integer> getKeys(HashMap<Integer, Integer> maps) {
    ArrayList<Integer> vals = new ArrayList<>();
    for (Map.Entry<Integer, Integer> map : maps.entrySet()) {
      vals.add(map.getKey());
    }
    return vals;
  }

  static ArrayList<Integer> getValues(HashMap<Integer, Integer> maps) {
    ArrayList<Integer> vals = new ArrayList<>();
    for (Map.Entry<Integer, Integer> map : maps.entrySet()) {
      vals.add(map.getValue());
    }
    return vals;
  }

  static int getMax(ArrayList<Integer> arr) {
    int max = arr.get(0);
    for (int i = 1; i < arr.size(); i++) {
      if (arr.get(i) > max) {
        max = arr.get(i);
      }
    }
    return max;
  }

  static int getMin(ArrayList<Integer> arr) {
    int max = arr.get(0);
    for (int i = 1; i < arr.size(); i++) {
      if (arr.get(i) < max) {
        max = arr.get(i);
      }
    }
    return max;
  }

  static int list[][] = { { -1, 0 }, { 0, 1 }, { 1, 0 }, { 0, -1 } };

  /*write your  methods and classes here*/

  public static void main(String[] args) throws IOException {
    String s = br.readLine();
    int n = s.length();
    if (
      (s.charAt(0) == '0' || s.charAt(0) == '_' || s.charAt(0) == 'X') &&
      s.length() == 1
    ) {
      bw.write("1\n");
      bw.flush();
    } else if (s.length() == 1) {
      bw.write("0\n");
      bw.flush();
    } else if (s.charAt(0) == '0') {
      bw.write("0\n");
      bw.flush();
    } else {
      String digits[] = { "25", "50", "75", "00" };
      String arr1[] = { "__", "_X", "X_", "XX" };
      int way[] = { 4, 4, 4, 1 };
      way[1] = s.charAt(0) == 'X' ? 2 : 4;
      way[2] = s.charAt(0) == 'X' ? 3 : 4;
      way[0] = s.length() == 2 ? 3 : 4;
      way[1] = s.length() == 2 ? 3 : 4;
      int ways = 0;
      String v = s.substring(n - 2, n);
      for (i = 0; i < 4; i++) {
        if (v.equals(digits[i])) {
          ways = 1;
        }
      }
      if (v.charAt(0) == '_' || v.charAt(0) == 'X') {
        ways = 2;
        if (v.charAt(1) == '0' && s.charAt(0) == 'X') {
          ways = 1;
        }
      } else if (v.charAt(1) == '_' || v.charAt(1) == 'X') {
        ways = 1;
      }
      for (i = 0; i < 4; i++) {
        if (v.equals(arr1[i])) {
          //System.out.println("age");
          ways = way[i];
        }
      }
      if (v == "XX" && s.charAt(0) == 'X') {
        ways = 0;
      }
      if (
        v.charAt(0) != '2' &&
        v.charAt(0) != '5' &&
        v.charAt(0) != '7' &&
        v.charAt(0) != '0' &&
        v.charAt(0) != 'X' &&
        v.charAt(0) != '_'
      ) {
        ways = 0;
      }
      if (
        v.charAt(1) != '0' &&
        v.charAt(1) != '5' &&
        v.charAt(1) != 'X' &&
        v.charAt(1) != '_'
      ) {
        ways = 0;
      }
      int xways = 1;
      if (v.charAt(0) == 'X') {
        xways = way[2];
      } else if (v.charAt(1) == 'X') {
        xways = way[1] / 2;
      } else {
        if (s.charAt(0) == 'X') {
          xways = 9;
        } else {
          xways = 10;
        }
      }

      boolean ok = false;
      long toti = 1l;
      for (i = 0; i < s.length() - 2; i++) {
        if (s.charAt(i) == 'X') {
          ok = true;
        }
        if (s.charAt(i) == '_') {
          if (i == 0) {
            toti *= 9l;
          } else {
            toti *= 10l;
          }
        }
      }
      if (ok) {
        toti *= 1l * xways;
      }
      toti *= 1l * ways;
      bw.write(Long.toString(toti) + "\n");
      bw.flush();
    }
  }
}


https://codeforces.com/problemset/submit/*
25
Any numbers that end in 00, 25, 50, or 75 will work - after can end in any groups of digits (can do casework on all possible endings) - just test if a certain starting group is possible - may also influence rest of string if one of the digits is an X
*/
import java.util.*;
import java.io.*;

public class Main{
  public static char[] str;
  public static String[] ends = {"00", "25", "50", "75"};
  public static long ret;
  public static void main(String[] args) throws IOException{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    str = br.readLine().toCharArray();
    ret = 0;
    if(str.length >= 2) for(int a = 0; a < 4; a++) match(str[str.length - 2], str[str.length - 1], ends[a]);
    else{
      if(str[0] == '0' || str[0] == 'X' || str[0] == '_') ret++; //only 0 possible, 0 divisible by 25
    }

    System.out.println(ret);

    br.close();
  }
  public static void match(char f, char s, String b){
    //assume a is from the original string, b is the checking string
    char f2 = f;
    char s2 = s;
    if(f == '_' && b.charAt(0) == '0' && str.length - 2 == 0) return;
    if(f2 == 'X'){
      //try to change f to the start of b
      f2 = b.charAt(0);
      if(s2 == 'X') s2 = b.charAt(0);
    }
    if(s2 == 'X'){
      //try to change s to the end of b
      s2 = b.charAt(1);
      if(f2 == 'X') f2 = b.charAt(1);
    }
    if(f2 == '_'){
      //try to change f to the start of b
      f2 = b.charAt(0);
    }
    if(s2 == '_'){
      //try to change s to the end of b
      s2 = b.charAt(1);
    }
    char cv = 'n'; //if f was X or s was X then xVal changes
    if(f == 'X') cv = f2;
    if(s == 'X') cv = s2;
    //System.out.println(f2 + " " + s2 + " " + b);
    if(f2 == b.charAt(0) && s2 == b.charAt(1)) poss(cv);
  }
  public static void poss(char xVal){
    //xVal = -1 if xs not filled yet
    //System.out.println("test " + xVal);
    if((xVal == '0' && str[0] == 'X') || str[0] == '0') return; //cannot start with a 0
    long add = 1;
    boolean xF = false; //whether or not we set X
    if(xVal != 'n') xF = true;
    for(int a = 0; a < str.length - 2; a++){
      if(str[a] == '_'){
        if(a == 0) add *= 9; //1 2 3 4 5 6 7 8 9
        else add *= 10;
      }
      if(!xF && str[a] == 'X'){
        xF = true;
        if(a == 0) add *= 9;
        else add *= 10;
      }
    }
    //System.out.println("add " + add);
    ret += add;
  }
}