import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
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);
        OutputWriter out = new OutputWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        int[] g(char[] x) {
            int[] r = new int[x.length + 1];
            for (int i = 1; i <= x.length; i++) {
                if (x[i - 1] != 'A') r[i] = 0;
                else {
                    r[i] = r[i - 1] + 1;
                }
            }
            return r;
        }

        int[] p(char[] x) {
            int[] r = new int[x.length + 1];
            for (int i = 1; i <= x.length; i++) {
                r[i] = r[i - 1] + (x[i - 1] == 'A' ? 0 : 1);
            }
            return r;
        }

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            char[] s = in.next().toCharArray();
            char[] t = in.next().toCharArray();
            int[] a1 = p(s), a2 = p(t);
            int[] r1 = g(s), r2 = g(t);
            int q = in.nextInt();
            while (q-- > 0) {
                int a = in.nextInt(), b = in.nextInt(), c = in.nextInt(), d = in.nextInt();
                int c1 = a1[b] - a1[a - 1], c2 = a2[d] - a2[c - 1];
                int x1 = Math.min(r1[b], b - a + 1), x2 = Math.min(r2[d], d - c + 1);
                if (x1 < x2) {
                    out.print("0");
                    continue;
                }
                if ((x1 - x2) % 3 != 0) {
                    if (c1 + 2 <= c2) {
                        c1 += 2;
                    } else {
                        out.print("0");
                        continue;
                    }
                }

                if (c2 == 0) {
                    if (c1 == 0) out.print("1");
                    else out.print("0");
                } else {
                    if (c1 > c2 || c1 % 2 != c2 % 2) out.print("0");
                    else out.print("1");
                }
            }
            out.println();
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1 << 16];
        private int curChar;
        private int numChars;

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

        public int read() {
            if (this.numChars == -1) {
                throw new InputMismatchException();
            } else {
                if (this.curChar >= this.numChars) {
                    this.curChar = 0;

                    try {
                        this.numChars = this.stream.read(this.buf);
                    } catch (IOException var2) {
                        throw new InputMismatchException();
                    }

                    if (this.numChars <= 0) {
                        return -1;
                    }
                }

                return this.buf[this.curChar++];
            }
        }

        public int nextInt() {
            int c;
            for (c = this.read(); isSpaceChar(c); c = this.read()) {
                ;
            }

            byte sgn = 1;
            if (c == 45) {
                sgn = -1;
                c = this.read();
            }

            int res = 0;

            while (c >= 48 && c <= 57) {
                res *= 10;
                res += c - 48;
                c = this.read();
                if (isSpaceChar(c)) {
                    return res * sgn;
                }
            }

            throw new InputMismatchException();
        }

        public String next() {
            int c;
            while (isSpaceChar(c = this.read())) {
                ;
            }

            StringBuilder result = new StringBuilder();
            result.appendCodePoint(c);

            while (!isSpaceChar(c = this.read())) {
                result.appendCodePoint(c);
            }

            return result.toString();
        }

        public static boolean isSpaceChar(int c) {
            return c == 32 || c == 10 || c == 13 || c == 9 || c == -1;
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void print(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                if (i != 0) {
                    writer.print(' ');
                }
                writer.print(objects[i]);
            }
        }

        public void println() {
            writer.println();
        }

        public void close() {
            writer.close();
        }

    }
}


//package round90re;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;

public class E {
	InputStream is;
	PrintWriter out;
	String INPUT = "";

	void solve()
	{
		int n = ni(), m = ni();
		double[][] co = new double[n][];
		for(int i = 0;i < n;i++){
			co[i] = new double[]{ni(), ni(), ni()};
		}
		for(int i = 0;i < m;i++){
			double[] nor = new double[]{ni(), ni(), ni()};
			double[][] nco = rot(nor, new double[]{0, 0, 1}, co);
			out.printf("%.20f\n", minBall(nco));
		}
	}

	public static double minBall(double[][] s)
	{
		double q = 0.5;
		double[] x = new double[2];

		double max = 0;
		while(q > 1E-11){
			for(int o = 0;o < 100;o++){
				max = -1;
				int maxi = -1;
				for(int i = 0;i < s.length;i++){
					double[] p = s[i];
					double v =
					(x[0]-p[0])*(x[0]-p[0])+
					(x[1]-p[1])*(x[1]-p[1]);
					if(v > max){
						max = v;
						maxi = i;
					}
				}

				for(int i = 0;i < 2;i++){
					x[i] += (s[maxi][i] - x[i])*q;
				}
			}
			q *= 0.6;
		}

		return Math.sqrt(max);
	}

	public static double[][] rot(double[] from, double[] to, double[][] xs)
	{
		double nfrom = Math.sqrt(from[0]*from[0]+from[1]*from[1]+from[2]*from[2]);
		for(int i = 0;i < 3;i++)from[i] /= nfrom;
		double nto = Math.sqrt(to[0]*to[0]+to[1]*to[1]+to[2]*to[2]);
		for(int i = 0;i < 3;i++)to[i] /= nto;
		double dot = from[0]*to[0]+from[1]*to[1]+from[2]*to[2];
		if(dot >= 1)dot = 1;
		if(dot <= -1)dot = -1;
		double angle = Math.acos(dot);
		if(Math.abs(angle) < 1E-8)return xs;

		double[] axis = new double[]{
				from[1]*to[2]-from[2]*to[1],
				from[2]*to[0]-from[0]*to[2],
				from[0]*to[1]-from[1]*to[0]
		};
		double nax = Math.sqrt(axis[0]*axis[0]+axis[1]*axis[1]+axis[2]*axis[2]);
		for(int i = 0;i < 3;i++)axis[i] /= nax;

		double[][] ret = new double[xs.length][3];

		double ncos = Math.cos(angle);
		double nsin = Math.sin(angle);
		double scos = 1.0 - ncos;

		double sxy = axis[0] * axis[1] * scos;
		double syz = axis[1] * axis[2] * scos;
		double sxz = axis[0] * axis[2] * scos;
		double sz = nsin * axis[2];
		double sy = nsin * axis[1];
		double sx = nsin * axis[0];

		int p = 0;
		for(double[] x : xs){
			ret[p][0] = (ncos+axis[0]*axis[0]*scos)*x[0] + (-sz+sxy)*x[1]+(sy+sxz)*x[2];
			ret[p][1] = (sz+sxy)*x[0]+(ncos+axis[1]*axis[1]*scos)*x[1]+(-sx+syz)*x[2];
			ret[p][2] = (-sy+sxz)*x[0]+(sx+syz)*x[1]+(ncos+axis[2]*axis[2]*scos)*x[2];
			p++;
		}
		return ret;
	}

	void run() throws Exception
	{
		is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);

		long s = System.currentTimeMillis();
		solve();
		out.flush();
		tr(System.currentTimeMillis()-s+"ms");
	}

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

	private byte[] inbuf = new byte[1024];
	private int lenbuf = 0, ptrbuf = 0;

	private int readByte()
	{
		if(lenbuf == -1)throw new InputMismatchException();
		if(ptrbuf >= lenbuf){
			ptrbuf = 0;
			try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
			if(lenbuf <= 0)return -1;
		}
		return inbuf[ptrbuf++];
	}

	private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
	private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }

	private double nd() { return Double.parseDouble(ns()); }
	private char nc() { return (char)skip(); }

	private String ns()
	{
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	private char[] ns(int n)
	{
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while(p < n && !(isSpaceChar(b))){
			buf[p++] = (char)b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}

	private char[][] nm(int n, int m)
	{
		char[][] map = new char[n][];
		for(int i = 0;i < n;i++)map[i] = ns(m);
		return map;
	}

	private int[] na(int n)
	{
		int[] a = new int[n];
		for(int i = 0;i < n;i++)a[i] = ni();
		return a;
	}

	private int ni()
	{
		int num = 0, b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}

		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private long nl()
	{
		long num = 0;
		int b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}

		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private boolean oj = System.getProperty("ONLINE_JUDGE") != null;
	private void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }
}


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

import java.util.*;

public class E {

	private final static boolean autoflush = false;

	public E () {
		int N = sc.nextInt(), M = sc.nextInt();
		double [][] X = toPrimitive(sc.nextDoubles(N));
		double [][] A = toPrimitive(sc.nextDoubles(M));

		for (int j : rep(M)) {
			Rodrigues R = new Rodrigues(A[j]);
			double [][] Y = new double [N][];
			for (int i : rep(N))
				Y[i] = R.rotate(project(X[i], A[j]));
			Circle res = Circle.toCircle(Y);
			print(res.R);
		}
	}

	///////////////////////////////////////////////////////////////////////////
	private static final double eps = 1e-9;
	private static final int INF = (int) 1e9;
	private static double [] cross (double [] X, double [] Y) { assert X.length <= 3 && Y.length <= 3; X = copyOf(X, 3); Y = copyOf(Y, 3); return new double [] { X[1]*Y[2] - Y[1]*X[2], X[2]*Y[0] - Y[2]*X[0], X[0]*Y[1] - Y[0]*X[1] }; }
	private static double [] diff (double [] X, double [] Y) { return sum(X, scalar(-1, Y)); }
	private static double dist (double [] X, double [] Y) { return norm(diff(X, Y)); }
	private static double dot(double [] X, double [] Y) { double res = 0; for (int i = 0; i < min(X.length, Y.length); ++i) res += X[i] * Y[i]; return res; }
	private static boolean eq(double x, double y) { return abs(x - y) < eps; }
	private static boolean eq (double [] X, double [] Y) { return eq(dist(X, Y), 0); }
	private static boolean greater(double x, double y) { return x > y + eps; }
	private static double norm (double ... X) { return sqrt(dot(X, X)); }
	private static double [] normalize(double ... X) { return eq(norm(X), 0) ? X : scalar(1/norm(X), X); }
	private static double [] project(double [] X, double [] K) { return diff(X, scalar(dot(X,K)/dot(K,K), K)); }
	private static int [] rep(int N) { return rep(0, N); }
	private static int [] rep(int S, int T) { if (T <= S) return new int [0]; int [] res = new int [T-S]; for (int i = S; i < T; ++i) res[i-S] = i; return res; }
	private static double [] scalar (double c, double ... X) { double [] res = new double [X.length]; for (int i = 0; i < X.length; ++i) res[i] = c * X[i]; return res; }
	private static double [] sum (double [] ... X) {
		int L = 0;
		for (double[] x : X)
			L = max(L, x.length);
		double [] res = new double [L];
		for (double[] x : X)
			for (int j = 0; j < x.length; ++j)
				res[j] += x[j];
		return res;
	}
	private static double [] toPrimitive(Double ... A) { double [] res = new double [A.length]; for (int i = 0; i < A.length; ++i) res[i] = A[i]; return res; }
	private static double [][] toPrimitive(Double [] ... A) { double [][] res = new double [A.length][]; for (int i = 0; i < A.length; ++i) res[i] = toPrimitive(A[i]); return res; }
	private static boolean zero(double ... X) { return eq(norm(X), 0); }
	////////////////////////////////////////////////////////////////////////////////////
	private static class Circle {
		public final double [] C;
		public final double R;
		public static final Circle R2 = new Circle(new double [2], INF);
		public Circle(double [] C, double R) { this.C = C; this.R = R; }
		public static Circle toCircumference(double [] ... X) {
			assert X.length > 0 && X.length <= 3;
			switch(X.length) {
			case 1: return new Circle(X[0], 0);
			case 2: return new Circle(scalar(.5, sum(X)), .5 * dist(X[0], X[1]));
			case 3:
				if (eq(X[0], X[1])) return toCircumference(X[1], X[2]);
				else if (eq(X[1], X[2])) return toCircumference(X[2], X[0]);
				else if (eq(X[2], X[0])) return toCircumference(X[0], X[1]);
				else return	calc(X[0], X[1], X[2]);
			default: throw new Error();
			}
		}
		public static Circle toCircle(double [] ... X) {
			assert X.length > 0; shuffle(asList(X));
			return welzl(X, X.length, new double[3][], 0);
		}
		private static Circle calc(double [] X, double [] Y, double [] Z) {
			boolean u = eq(X[0], Y[0]), v = eq(Y[0], Z[0]);
			if (u && v) return R2;
			else if (u) return calc(Y, Z, X);
			else if (v) return calc(Z, X, Y);
			else {
				double U = (Y[1] - X[1]) / (Y[0] - X[0]);
				double V = (Z[1] - Y[1]) / (Z[0] - Y[0]);
				if (eq(U, V)) return R2;
				if (eq(U, 0)) return calc(Z, Y, X);
				double CX = (U * V * (X[1] - Z[1]) + V * (X[0] + Y[0]) - U * (Y[0] + Z[0])) / (2 * (V - U));
				double CY = ((X[0] + Y[0]) / 2 - CX) / U + (X[1] + Y[1]) / 2;
				double [] C = new double [] { CX, CY };
				double R = dist(C, X); assert eq(dist(C, Y), R) && eq(dist(C, Z), R);
				return new Circle(C, R);
			}
		}
		private static Circle welzl(double [][] X, int N, double [][] S, int K) {
			if (K == 3) return Circle.toCircumference(S);
			else if (N == 0) {
				switch(K) {
				case 0: return new Circle(new double [3], -1);
				case 1: return new Circle(S[0], 0);
				case 2: return Circle.toCircumference(S[0], S[1]);
				default: throw new Error();
				}
			}
			else {
				Circle C = welzl(X, N-1, S, K);
				if (greater(dist(C.C, X[N-1]), C.R)) {
					S[K++] = X[N-1];
					C = welzl(X, N-1, S, K);
				}
				return C;
			}
		}
		public String toString() { Map<String, Object> M = new HashMap<>(); M.put("C", Arrays.toString(C)); M.put("R", R); return M.toString(); }
	}
	private static class Rodrigues {
		private final double [] K, T;
		public Rodrigues(double ... A) {
			assert A.length <= 3; A = copyOf(A, 3);
			K = normalize(new double [] { -A[1], A[0] }); double [] L = new double [] { K[1], -K[0] };
			if (!zero(K)) {
				double [] V = new double [3];
				while (zero(V))
					V = project(project(new double [] { random(), random(), random() }, A), K);
				T = normalize(new double [] { dot(L, V), V[2] });
			} else
				T = null;
		}
		public double [] rotate(double ... X) {
			assert X.length <= 3; X = copyOf(X, 3);
			if (T != null) {
				double [] Y = scalar(T[0], X);
				Y = sum(Y, scalar(T[1], cross(K, X)));
				X = sum(Y, scalar(dot(K, X) * (1 - T[0]), K));
			}
			assert eq(X[2], 0);
			return copyOf(X, 2);
		}
	}
	////////////////////////////////////////////////////////////////////////////////////
	private final static IOUtils.MyScanner sc = new IOUtils.MyScanner();
	private static void print (Object o, Object ... A) { IOUtils.print(o, A); }
	private static void exit() { IOUtils.exit(); }
	private static class IOUtils {
		public static class MyScanner {
			public String next() { newLine(); return line[index++]; }
			public int nextInt() { return Integer.parseInt(next()); }
			public String nextLine() { line = null; return readLine(); }
			public String [] nextStrings() { return nextLine().split(" "); }
			public Double [] nextDoubles() {
				String [] L = nextStrings();
				Double [] res = new Double [L.length];
				for (int i = 0; i < L.length; ++i)
					res[i] = Double.parseDouble(L[i]);
				return res;
			}
			public Double [][] nextDoubles (int N) {
				Double [][] res = new Double [N][];
				for (int i = 0; i < N; ++i)
					res[i] = nextDoubles();
				return res;
			}
			//////////////////////////////////////////////
			private boolean eol() { return index == line.length; }
			private String readLine() {
				try {
					return r.readLine();
				} catch (Exception e) {
					throw new Error (e);
				}
			}
			private final java.io.BufferedReader r;
			private MyScanner () { this(new java.io.BufferedReader(new java.io.InputStreamReader(System.in))); }
			private MyScanner (java.io.BufferedReader r) {
				try {
					this.r = r;
					while (!r.ready())
						Thread.sleep(1);
					start();
				} catch (Exception e) {
					throw new Error(e);
				}
			}
			private String [] line;
			private int index;
			private void newLine() {
				if (line == null || eol()) {
					line = readLine().split(" ");
					index = 0;
				}
			}
		}
		private static String build(Object o, Object ... A) { return buildDelim(" ", o, A); }
		private static String buildDelim(String delim, Object o, Object ... A) {
			StringBuilder b = new StringBuilder();
			append(b, o, delim);
			for (Object p : A)
				append(b, p, delim);
			return b.substring(delim.length());
		}
		//////////////////////////////////////////////////////////////////////////////////
		private static void start() { if (t == 0) t = millis(); }
		private static void append(StringBuilder b, Object o, String delim) {
			if (o.getClass().isArray()) {
				int len = java.lang.reflect.Array.getLength(o);
				for (int i = 0; i < len; ++i)
					append(b, java.lang.reflect.Array.get(o, i), delim);
			} else if (o instanceof Iterable<?>)
				for (Object p : (Iterable<?>) o)
					append(b, p, delim);
			else {
				if (o instanceof Double)
					o = new java.text.DecimalFormat("#.############").format(o);
				b.append(delim).append(o);
			}
		}
		private static java.io.PrintWriter pw = new java.io.PrintWriter(System.out, autoflush);
		private static void print(Object o, Object ... A) { pw.println(build(o, A)); }
		private static void err(Object o, Object ... A) { System.err.println(build(o, A)); }
		private static void exit() {
			IOUtils.pw.close();
			System.out.flush();
			err("------------------");
			err(IOUtils.time());
		}
		private static long t;
		private static long millis() { return System.currentTimeMillis(); }
		private static String time() { return "Time: " + (millis() - t) / 1000.0; }
	}
	public static void main (String[] args) { new E(); exit(); }
}


import java.util.Scanner;
import java.util.SortedMap;
import java.util.TreeMap;

public class E {

	private static final double EPS = 1e-8;

   	private E (Scanner sc) {
		int N = sc.nextInt();
		int M = sc.nextInt();

		double [][] X = new double [N][];
		for (int i = 0; i < N; ++i)
			X[i] = new double [] { sc.nextInt(),sc.nextInt(),sc.nextInt() };

		double [][] A = new double [M][];
		for (int i = 0; i < M; ++i)
			A[i] = new double [] { sc.nextInt(),sc.nextInt(),sc.nextInt() };
		for (int i = 0; i < M; ++i)
			solve(X, A[i]);
	}

	private void solve (double [][] X, double [] A) {
		// Project X on plane
		double [][] Y = new double [X.length][];
		for (int i = 0; i < X.length; ++i)
			Y[i] = project(X[i], A);

		// Rotate plane, so that z = 0
		double [] K = new double [] { -A[1], A[0], 0 };
		if (!isZero(K))
			Y = rodrigues(Y, normalize(K));

		// Welzl Algorithm
		Y = randomize(Y);
		double [][] S = new double [3][];
		double [] C = welzl(Y, Y.length, S, 0);

		print(C[C.length - 1]);
	}

	double [] project(double [] X, double [] A) {
		return diff(X, scalar(dot(X,A)/dot(A,A), A));
	}

	double [][] rodrigues(double [][] X, double [] K) {
		// Rotate X plane to z=0, around K axis
		// K is a unit vector in both X and z=0 planes
		double [] V = null;
		for (double [] x : X) {
			// Use a vector V on X plane, orthogonal to K,
			// to easily compute sin and cos of rotation angle.
			double [] v = project(x,K);
			if (!isZero(v))
				V = v;
		}

		if (V == null)
			return X;

		double [] T = new double [] {
			dot(new double [] { K[1], -K[0], 0 }, V),
			V[2] };
		T = normalize(T);

		for (int i = 0; i < X.length; ++i) {
			double [] x = scalar(T[0] ,X[i]);
			x = sum(x, scalar(T[1] ,cross(K,X[i])));
			x = sum(x, scalar(dot(K,X[i])*(1-T[0]), K));
			X[i] = x;
		}
		return X;
	}

	double [] welzl(double [][] X, int N, double [][] S, int B) {
		if (B == 3)
			return circle(S[0], S[1], S[2]);
		else if (N == 1 && B == 0)
			return new double [] { X[0][0], X[0][1], X[0][2], 0 };
		else if (N == 0 && B == 2)
			return circle (S[0], S[1]);
		else if (N == 1 && B == 1)
			return circle (S[0], X[0]);
		else {
			double [] C = welzl(X, N-1, S, B);
			if (dist (new double [] { C[0], C[1], C[2] }, X[N-1]) > C[3] + EPS) {
				S[B++] = X[N-1];
				C = welzl(X, N-1, S, B);
			}
			return C;
		}
	}

	double [] circle(double [] a, double [] b) {
		double d = dist(a,b);
		double [] C = new double [a.length+1];
		for (int i = 0; i < a.length; ++i)
			C[i] = (a[i] + b[i])/2;
		C[a.length] = d/2;
		return C;
	}

	boolean close(double x, double y) {
		return Math.abs(x-y) < EPS;
	}

	double [] circle(double [] a, double [] b, double [] c) {
		if (close(a[0],b[0]) && close(b[0],c[0]))
			return collinear(a,b,c);
		else if (close(a[0],b[0]))
			return circle(b,c,a);
		else if (close(b[0],c[0]))
			return circle(c,a,b);
		else {
			double ma = (b[1] - a[1])/(b[0] - a[0]);
			if (close(ma,0))
				return circle(c,b,a);
			double mb = (c[1] - b[1])/(c[0] - b[0]);
			if (close(ma,mb))
				return collinear(a,b,c);
			double [] C = new double [4];
			C[0] = (ma * mb * (a[1] - c[1]) + mb * (a[0] + b[0]) - ma * (b[0] + c[0])) / (2*(mb - ma));
			C[1] = ((a[0] + b[0])/2 - C[0])/ma + (a[1] + b[1])/2;
			C[3] = dist(a,C);
			return C;
		}
	}

	double [] collinear (double [] a, double [] b, double [] c) {
		double [] C = circle(a,b);
		if (dist(b,c) > dist(a,b))
			C = circle(b,c);
		if (dist(a,c) > dist(b,c))
			C = circle(a,c);
		return C;
	}

	double [][] randomize(double [][] X) {
		SortedMap<Double, double []> M = new TreeMap<Double, double []>();
		for (double [] x : X)
			M.put(Math.random(), x);
		return M.values().toArray(new double[0][]);
	}

	////////////////////////////////////////////////////////////////////////////////////

	double dot(double [] A, double [] B) {
		double S = 0;
		for (int i = 0; i < A.length; ++i)
			S += A[i] * B[i];
		return S;
	}

	double norm (double [] A) {
		return Math.sqrt(dot(A,A));
	}

	boolean isZero(double [] X) {
		return close(dot(X,X),0);
	}

	double [] normalize(double [] X) {
		return scalar(1/norm(X),X);
	}

	double dist (double [] A, double [] B) {
		return norm(diff(A,B));
	}

	double [] scalar (double c, double [] A) {
		double [] cA = new double [A.length];
		for (int i = 0; i < A.length; ++i)
			cA[i] = c * A[i];
		return cA;
	}

	double [] sum (double [] A, double [] B) {
		double [] C = new double [A.length];
		for (int i = 0; i < A.length; ++i)
			C[i] = A[i] + B[i];
		return C;
	}

	double [] diff (double [] A, double [] B) {
		double [] C = new double [A.length];
		for (int i = 0; i < A.length; ++i)
			C[i] = A[i] - B[i];
		return C;
	}

	double [] cross (double [] A, double [] B) {
		double [] C = new double [A.length];
		// TODO - This is only 3-dimensional
		C[0] = A[1]*B[2] - B[1]*A[2];
		C[1] = A[2]*B[0] - B[2]*A[0];
		C[2] = A[0]*B[1] - B[0]*A[1];
		return C;
	}

	////////////////////////////////////////////////////////////////////////////////////

	private void print (Object o) {
		System.out.println(o);
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		new E(sc);
	}
}


//package round90re;
import java.awt.geom.Line2D;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;

public class E {
	InputStream is;
	PrintWriter out;
	String INPUT = "";

	void solve()
	{
		int n = ni(), m = ni();
		double[][] co = new double[n][];
		for(int i = 0;i < n;i++){
			co[i] = new double[]{ni(), ni(), ni()};
		}
		for(int i = 0;i < m;i++){
			double[] nor = new double[]{ni(), ni(), ni()};
			double[][] nco = rot(nor, new double[]{0, 0, 1}, co);
			out.printf("%.15f\n", minCircle(nco));
		}
	}

	public double minCircle(double[][] co)
	{
		int n = co.length;
		if(n <= 1)return 0;

		// 最遠点を選ぶ
		double maxd = -1;
		int first = -1;
		for(int i = 0;i < n;i++){
			double d2 = co[i][0]*co[i][0]+co[i][1]*co[i][1];
			if(d2 > maxd){
				maxd = d2;
				first = i;
			}
		}

		// 2点に接するように最遠点に近づいていく
		// (tx,ty)が(x,y)-(x',y')の垂直二等分線をとおるような最小のt
		// (T-M)*L=0
		// t(x*Lx+y*Ly)=mx*Lx+my*Ly
		double mint = 1.01;
		int second = -1;
		double fx = co[first][0], fy = co[first][1];
		for(int i = 0;i < n;i++){
			if(i == first)continue;
			double ox = co[i][0], oy = co[i][1];
			double mx = (fx+ox)/2, my = (fy+oy)/2;
			double t = (mx*(ox-fx)+my*(oy-fy))/(fx*(ox-fx)+fy*(oy-fy));
			if(t < mint){
				mint = t;
				second = i;
			}
		}
		if(second == -1){ // secondがない場合縮重している
			return 0;
		}

		boolean[] sed = new boolean[n];
		sed[first] = true;
		sed[second] = true;

		// CをMに近づけていく
		int third = -1;
		while(true){
			double mx = (co[first][0] + co[second][0])/2;
			double my = (co[first][1] + co[second][1])/2;
			double nr2 = (mx-co[first][0])*(mx-co[first][0])+(my-co[first][1])*(my-co[first][1]);
			double[] ec = null;
			third = -1;
			for(int i = 0;i < n;i++){
				if(sed[i])continue;
//				if(i == first || i == second)continue;
				if((mx-co[i][0])*(mx-co[i][0])+(my-co[i][1])*(my-co[i][1]) <= nr2)continue;
				double[] lec = excircle2(co[first][0], co[first][1], co[second][0], co[second][1], co[i][0], co[i][1]);
				if(ec == null || lec[2] > ec[2]){
					ec = lec;
					third = i;
				}
			}
			if(ec == null)break;
			sed[third] = true;
			if(Line2D.linesIntersect(co[first][0], co[first][1], co[third][0], co[third][1], ec[0], ec[1], co[second][0], co[second][1])){
				second = third;
				continue;
			}
			if(Line2D.linesIntersect(co[second][0], co[second][1], co[third][0], co[third][1], ec[0], ec[1], co[first][0], co[first][1])){
				first = third;
				continue;
			}
			return ec[2];
		}
		return Math.sqrt((co[second][0]-co[first][0])*(co[second][0]-co[first][0])+(co[second][1]-co[first][1])*(co[second][1]-co[first][1]))/2;
	}

	public static double[] excircle2(double ax, double ay, double bx, double by, double cx, double cy)
	{
		double A = (bx-cx)*(bx-cx)+(by-cy)*(by-cy);
		double B = (cx-ax)*(cx-ax)+(cy-ay)*(cy-ay);
		double C = (ax-bx)*(ax-bx)+(ay-by)*(ay-by);
		double D = A*(-A+B+C)+B*(A-B+C)+C*(A+B-C);
		double X = (A*(-A+B+C)*ax + B*(A-B+C)*bx + C*(A+B-C)*cx) / D;
		double Y = (A*(-A+B+C)*ay + B*(A-B+C)*by + C*(A+B-C)*cy) / D;
		double R = Math.sqrt((X-ax)*(X-ax)+(Y-ay)*(Y-ay));
//		double R = A*B*C/Math.sqrt((A+B+C)*(-A+B+C)*(A-B+C)*(A+B-C));
		return new double[]{X, Y, R};
	}

	public static double[][] rot(double[] from, double[] to, double[][] xs)
	{
		double nfrom = Math.sqrt(from[0]*from[0]+from[1]*from[1]+from[2]*from[2]);
		for(int i = 0;i < 3;i++)from[i] /= nfrom;
		double nto = Math.sqrt(to[0]*to[0]+to[1]*to[1]+to[2]*to[2]);
		for(int i = 0;i < 3;i++)to[i] /= nto;
		double dot = from[0]*to[0]+from[1]*to[1]+from[2]*to[2];
		if(dot >= 1)dot = 1;
		if(dot <= -1)dot = -1;
		double angle = Math.acos(dot);
		if(Math.abs(angle) < 1E-8)return xs;

		double[] axis = new double[]{
				from[1]*to[2]-from[2]*to[1],
				from[2]*to[0]-from[0]*to[2],
				from[0]*to[1]-from[1]*to[0]
		};
		double nax = Math.sqrt(axis[0]*axis[0]+axis[1]*axis[1]+axis[2]*axis[2]);
		for(int i = 0;i < 3;i++)axis[i] /= nax;

		double[][] ret = new double[xs.length][3];

		double ncos = Math.cos(angle);
		double nsin = Math.sin(angle);
		double scos = 1.0 - ncos;

		double sxy = axis[0] * axis[1] * scos;
		double syz = axis[1] * axis[2] * scos;
		double sxz = axis[0] * axis[2] * scos;
		double sz = nsin * axis[2];
		double sy = nsin * axis[1];
		double sx = nsin * axis[0];

		int p = 0;
		for(double[] x : xs){
			ret[p][0] = (ncos+axis[0]*axis[0]*scos)*x[0] + (-sz+sxy)*x[1]+(sy+sxz)*x[2];
			ret[p][1] = (sz+sxy)*x[0]+(ncos+axis[1]*axis[1]*scos)*x[1]+(-sx+syz)*x[2];
			ret[p][2] = (-sy+sxz)*x[0]+(sx+syz)*x[1]+(ncos+axis[2]*axis[2]*scos)*x[2];
			p++;
		}
		return ret;
	}

	void run() throws Exception
	{
		is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);

		long s = System.currentTimeMillis();
		solve();
		out.flush();
		tr(System.currentTimeMillis()-s+"ms");
	}

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

	private byte[] inbuf = new byte[1024];
	private int lenbuf = 0, ptrbuf = 0;

	private int readByte()
	{
		if(lenbuf == -1)throw new InputMismatchException();
		if(ptrbuf >= lenbuf){
			ptrbuf = 0;
			try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
			if(lenbuf <= 0)return -1;
		}
		return inbuf[ptrbuf++];
	}

	private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
	private int ni()
	{
		int num = 0, b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}

		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private boolean oj = System.getProperty("ONLINE_JUDGE") != null;
	private void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }
}


/**
 * JUDGE_ID : 104262PN
 * User     : Денис
 * Date     : 27.04.11
 * Time     : 17:53
 * ICQ      : 785625
 * Email    : popokus@gmail.com
 */

import java.io.*;

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

    int nextInt() throws IOException {
        in.nextToken();
        return (int) in.nval;
    }

    StreamTokenizer in;
    Writer writer;
    Reader reader;

    void run() throws IOException {
        boolean oj = System.getProperty("ONLINE_JUDGE") != null;
        reader = oj ? new InputStreamReader(System.in, "ISO-8859-1") : new FileReader("input/is70_d.txt");
        writer = new OutputStreamWriter(System.out, "ISO-8859-1");
        in = new StreamTokenizer(new BufferedReader(reader));
        PrintWriter out = new PrintWriter(writer);
        int R = nextInt();
        double full = Math.sqrt(3);
        double half = full / 2;
        Hexagen hexagen = new Hexagen(  0, 0,
                                       0.5 , half,
                                       1   , 0,
                                       0.5 , -half,
                                      -0.5 , -half,
                                      -1   , 0,
                                      -0.5 , half);

        int count = 0;
        // up, up-right, down-right, down, down-left, up-left
        int[] xC    = {0, 1, 1, 0, -1, -1};
        int[] yC    = {1, 1, 0, -1, -1, 0};

        double[] dx = {0,             1 + 0.5,        1 + 0.5,       0            , - 1 - 0.5        ,  - 1 - 0.5 };
        double[] dy = {full, half, -half, -full, - half, half};
        boolean up  = true;
        while (true) {
            int index;
            if (up) {
                index = 0;
            } else {
                index = 3;
            }
            Hexagen  h = new Hexagen(hexagen.xCord + xC[index], hexagen.yCord + yC[index],
                       hexagen.x1 + dx[index], hexagen.y1 + dy[index],
                       hexagen.x2 + dx[index], hexagen.y2 + dy[index],
                       hexagen.x3 + dx[index], hexagen.y3 + dy[index],
                       hexagen.x4 + dx[index], hexagen.y4 + dy[index],
                       hexagen.x5 + dx[index], hexagen.y5 + dy[index],
                       hexagen.x6 + dx[index], hexagen.y6 + dy[index]);
            if (!isOnCircle(R, h.x1, h.y1,
                            h.x2, h.y2 ,
                            h.x3, h.y3,
                            h.x4, h.y4,
                            h.x5, h.y5,
                            h.x6, h.y6)) {
                if ((h.y3 > R && up) || (!up && -h.y1 > R)) {
                    if (up) {
                        up = false;
                        // shift to right-up
                        index = 1;
                    } else {
                        up = true;
                        // shift to right-down
                        index = 2;
                    }
                    hexagen = new Hexagen(hexagen.xCord + xC[index], hexagen.yCord + yC[index],
                            hexagen.x1 + dx[index], hexagen.y1 + dy[index],
                            hexagen.x2 + dx[index], hexagen.y2 + dy[index],
                            hexagen.x3 + dx[index], hexagen.y3 + dy[index],
                            hexagen.x4 + dx[index], hexagen.y4 + dy[index],
                            hexagen.x5 + dx[index], hexagen.y5 + dy[index],
                            hexagen.x6 + dx[index], hexagen.y6 + dy[index]);
                    if (hexagen.x2 > R)
                        break;
                } else {
                    hexagen = h;
                }
            } else {
                hexagen = h;
                count++;
            }
        }
        out.println(count*2 + 1);
        out.flush();
        out.close();
    }
    boolean isOnCircle(int radius, double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4, double x5, double y5, double x6, double y6)  {
        double d1 =  Math.sqrt(x1 * x1 + y1 * y1);
        double d2 =  Math.sqrt(x2 * x2 + y2 * y2);
        double d3 =  Math.sqrt(x3 * x3 + y3 * y3);
        double d4 =  Math.sqrt(x4 * x4 + y4 * y4);
        double d5 =  Math.sqrt(x5 * x5 + y5 * y5);
        double d6 =  Math.sqrt(x6 * x6 + y6 * y6);
        if (d1 > radius &&  d1 - radius > 1e-6) return false;
        if (d2 > radius &&  d2 - radius > 1e-6) return false;
        if (d3 > radius &&  d3 - radius > 1e-6) return false;
        if (d4 > radius &&  d4 - radius > 1e-6) return false;
        if (d5 > radius &&  d5 - radius > 1e-6) return false;
        if (d6 > radius &&  d6 - radius > 1e-6) return false;
        return true;
    }

    }

    class Hexagen {
        int xCord;
        int yCord;
        double x1, x2, x3, x4, x5, x6;
        double y1, y2, y3, y4, y5, y6;
        Hexagen(int xCord, int yCord, double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4, double x5, double y5, double x6, double y6) {
            this.xCord = xCord;
            this.yCord = yCord;
            this.x1 = x1;
            this.x2 = x2;
            this.x3 = x3;
            this.x4 = x4;
            this.x5 = x5;
            this.x6 = x6;

            this.y1 = y1;
            this.y2 = y2;
            this.y3 = y3;
            this.y4 = y4;
            this.y5 = y5;
            this.y6 = y6;
        }
    }


/**
 * JUDGE_ID : 104262PN
 * User     : Денис
 * Date     : 27.04.11
 * Time     : 17:53
 * ICQ      : 785625
 * Email    : popokus@gmail.com
 */

import java.io.*;

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

    int nextInt() throws IOException {
        in.nextToken();
        return (int) in.nval;
    }

    StreamTokenizer in;
    Writer writer;
    Reader reader;

    void run() throws IOException {
        boolean oj = System.getProperty("ONLINE_JUDGE") != null;
        reader = oj ? new InputStreamReader(System.in, "ISO-8859-1") : new FileReader("input/is70_d.txt");
        writer = new OutputStreamWriter(System.out, "ISO-8859-1");
        in = new StreamTokenizer(new BufferedReader(reader));
        PrintWriter out = new PrintWriter(writer);
        int R = nextInt();
        double full = Math.sqrt(3);
        double half = full / 2;
        Hexagen hexagen = new Hexagen(
                                       0.5 , half,
                                       1   , 0,
                                       0.5 , -half,
                                      -0.5 , -half,
                                      -1   , 0,
                                      -0.5 , half);

        long count = 0;
        // up, up-right, down-right, down, down-left, up-left
        int[] xC    = {0, 1, 1, 0, -1, -1};
        int[] yC    = {1, 1, 0, -1, -1, 0};

        double[] dx = {0,             1 + 0.5,        1 + 0.5,       0            , - 1 - 0.5        ,  - 1 - 0.5 };
        double[] dy = {full, half, -half, -full, - half, half};
        boolean up  = true;
        while (true) {
            int index;
            if (up) {
                index = 0;
            } else {
                index = 3;
            }
            Hexagen  h = new Hexagen(
                       hexagen.x1 + dx[index], hexagen.y1 + dy[index],
                       hexagen.x2 + dx[index], hexagen.y2 + dy[index],
                       hexagen.x3 + dx[index], hexagen.y3 + dy[index],
                       hexagen.x4 + dx[index], hexagen.y4 + dy[index],
                       hexagen.x5 + dx[index], hexagen.y5 + dy[index],
                       hexagen.x6 + dx[index], hexagen.y6 + dy[index]);
            if (!isOnCircle(R, h.x1, h.y1,
                            h.x2, h.y2 ,
                            h.x3, h.y3,
                            h.x4, h.y4,
                            h.x5, h.y5,
                            h.x6, h.y6)) {
                if ((h.y3 > R && up) || (!up && -h.y1 > R)) {
                    if (up) {
                        up = false;
                        // shift to right-up
                        index = 1;
                    } else {
                        up = true;
                        // shift to right-down
                        index = 2;
                    }
                    hexagen = new Hexagen(
                            hexagen.x1 + dx[index], hexagen.y1 + dy[index],
                            hexagen.x2 + dx[index], hexagen.y2 + dy[index],
                            hexagen.x3 + dx[index], hexagen.y3 + dy[index],
                            hexagen.x4 + dx[index], hexagen.y4 + dy[index],
                            hexagen.x5 + dx[index], hexagen.y5 + dy[index],
                            hexagen.x6 + dx[index], hexagen.y6 + dy[index]);
                    if (hexagen.x2 > R)
                        break;
                } else {
                    hexagen = h;
                }
            } else {
                hexagen = h;
                count++;
            }
        }
        out.println(count*2 + 1);
        out.flush();
        out.close();
    }
    boolean isOnCircle(int radius, double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4, double x5, double y5, double x6, double y6)  {
        double d1 =  Math.sqrt(x1 * x1 + y1 * y1);
        double d2 =  Math.sqrt(x2 * x2 + y2 * y2);
        double d3 =  Math.sqrt(x3 * x3 + y3 * y3);
        double d4 =  Math.sqrt(x4 * x4 + y4 * y4);
        double d5 =  Math.sqrt(x5 * x5 + y5 * y5);
        double d6 =  Math.sqrt(x6 * x6 + y6 * y6);
        if (d1 > radius &&  d1 - radius > 1e-6) return false;
        if (d2 > radius &&  d2 - radius > 1e-6) return false;
        if (d3 > radius &&  d3 - radius > 1e-6) return false;
        if (d4 > radius &&  d4 - radius > 1e-6) return false;
        if (d5 > radius &&  d5 - radius > 1e-6) return false;
        if (d6 > radius &&  d6 - radius > 1e-6) return false;
        return true;
    }

    }

    class Hexagen {
        double x1, x2, x3, x4, x5, x6;
        double y1, y2, y3, y4, y5, y6;
        Hexagen(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4, double x5, double y5, double x6, double y6) {
            this.x1 = x1;
            this.x2 = x2;
            this.x3 = x3;
            this.x4 = x4;
            this.x5 = x5;
            this.x6 = x6;

            this.y1 = y1;
            this.y2 = y2;
            this.y3 = y3;
            this.y4 = y4;
            this.y5 = y5;
            this.y6 = y6;
        }
    }


/**
 * JUDGE_ID : 104262PN
 * User     : Денис
 * Date     : 27.04.11
 * Time     : 17:53
 * ICQ      : 785625
 * Email    : popokus@gmail.com
 */

import java.io.*;

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

    int nextInt() throws IOException {
        in.nextToken();
        return (int) in.nval;
    }

    StreamTokenizer in;
    Writer writer;
    Reader reader;

    void run() throws IOException {
        boolean oj = System.getProperty("ONLINE_JUDGE") != null;
        reader = oj ? new InputStreamReader(System.in, "ISO-8859-1") : new FileReader("input/is70_d.txt");
        writer = new OutputStreamWriter(System.out, "ISO-8859-1");
        in = new StreamTokenizer(new BufferedReader(reader));
        PrintWriter out = new PrintWriter(writer);
        int R = nextInt();
        double full = Math.sqrt(3);
        double half = full / 2;
        Hexagen hexagen = new Hexagen(
                                       0.5 , half,
                                       1   , 0,
                                       0.5 , -half,
                                      -0.5 , -half,
                                      -1   , 0,
                                      -0.5 , half);

        long count = 0;
        // up, up-right, down-right, down, down-left, up-left
        int[] xC    = {0, 1, 1, 0, -1, -1};
        int[] yC    = {1, 1, 0, -1, -1, 0};

        double[] dx = {0,             1 + 0.5,        1 + 0.5,       0            , - 1 - 0.5        ,  - 1 - 0.5 };
        double[] dy = {full, half, -half, -full, - half, half};
        boolean up  = true;
        while (true) {
            int index;
            if (up) {
                index = 0;
            } else {
                index = 3;
            }
            Hexagen  h = new Hexagen(
                       hexagen.x1 + dx[index], hexagen.y1 + dy[index],
                       hexagen.x2 + dx[index], hexagen.y2 + dy[index],
                       hexagen.x3 + dx[index], hexagen.y3 + dy[index],
                       hexagen.x4 + dx[index], hexagen.y4 + dy[index],
                       hexagen.x5 + dx[index], hexagen.y5 + dy[index],
                       hexagen.x6 + dx[index], hexagen.y6 + dy[index]);
            if (!isOnCircle(R, h.x1, h.y1,
                            h.x2, h.y2 ,
                            h.x3, h.y3,
                            h.x4, h.y4,
                            h.x5, h.y5,
                            h.x6, h.y6)) {
                if ((h.y3 > R && up) || (!up && -h.y1 > R)) {
                    if (up) {
                        up = false;
                        // shift to right-up
                        index = 1;
                    } else {
                        up = true;
                        // shift to right-down
                        index = 2;
                    }
                    hexagen = new Hexagen(
                            hexagen.x1 + dx[index], hexagen.y1 + dy[index],
                            hexagen.x2 + dx[index], hexagen.y2 + dy[index],
                            hexagen.x3 + dx[index], hexagen.y3 + dy[index],
                            hexagen.x4 + dx[index], hexagen.y4 + dy[index],
                            hexagen.x5 + dx[index], hexagen.y5 + dy[index],
                            hexagen.x6 + dx[index], hexagen.y6 + dy[index]);
                    if (hexagen.x2 > R)
                        break;
                } else {
                    hexagen = h;
                }
            } else {
                hexagen = h;
                count++;
            }
        }
        out.println(count * 2 + 1);
        out.flush();
        out.close();
    }
    boolean isOnCircle(int radius, double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4, double x5, double y5, double x6, double y6)  {
        double d1 =  Math.sqrt(x1 * x1 + y1 * y1);
        if (d1 > radius &&  d1 - radius > 1e-6) return false;
        double d2 =  Math.sqrt(x2 * x2 + y2 * y2);
        if (d2 > radius &&  d2 - radius > 1e-6) return false;
        double d3 =  Math.sqrt(x3 * x3 + y3 * y3);
        if (d3 > radius &&  d3 - radius > 1e-6) return false;
        double d4 =  Math.sqrt(x4 * x4 + y4 * y4);
        if (d4 > radius &&  d4 - radius > 1e-6) return false;
        double d5 =  Math.sqrt(x5 * x5 + y5 * y5);
        if (d5 > radius &&  d5 - radius > 1e-6) return false;
        double d6 =  Math.sqrt(x6 * x6 + y6 * y6);
        if (d6 > radius &&  d6 - radius > 1e-6) return false;
        return true;
    }

    }

    class Hexagen {
        double x1, x2, x3, x4, x5, x6;
        double y1, y2, y3, y4, y5, y6;
        Hexagen(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4, double x5, double y5, double x6, double y6) {
            this.x1 = x1;
            this.x2 = x2;
            this.x3 = x3;
            this.x4 = x4;
            this.x5 = x5;
            this.x6 = x6;

            this.y1 = y1;
            this.y2 = y2;
            this.y3 = y3;
            this.y4 = y4;
            this.y5 = y5;
            this.y6 = y6;
        }
    }


import java.util.*;
public class ArchersShot {
	public static void main(String[] Args){
		Scanner sc = new Scanner(System.in);
		long n = sc.nextInt();
		if(n<=2){
			System.out.println(1);
		}
		else{
			long ans = 1;
			boolean done = false;
			int dist = 2;
			int layer = 0;
			while(!done){
				double dDist = dist + .5;
				layer++;
				long hi = layer + 1;
				long lo = 0;
				while(lo != hi - 1){
					long mid = (hi + lo) / 2;
					if(dDist*dDist + (mid * 2 - 1) * (mid * 2 - 1) * 3.0 / 4 <= n * n + 1e-9)
						lo = mid;
					else
						hi = mid;
				}
				if(lo == 0)break;
				ans += 6 * lo * 2;
				if(lo == layer)
					ans-=6;
				dDist = dist + 2;
				hi = layer + 2;
				lo = 0;
				while(lo != hi - 1){
					long mid = (hi + lo) / 2;
					if(dDist*dDist + (mid - 1) * (mid - 1) * 3.0 <= n * n + 1e-9)
						lo = mid;
					else
						hi = mid;
				}
				if(lo == 0)break;
				ans += 6 * lo;
				dist += 3;
			}
			System.out.println(ans);
		}
	}
	public static long get(int k){
		return ((k*1l*(k-1)) / 2) * 6 +1
	}
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Arrays;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.io.Closeable;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) throws Exception {
        Thread thread = new Thread(null, new TaskAdapter(), "", 1 << 27);
        thread.start();
        thread.join();
    }

    static class TaskAdapter implements Runnable {
        @Override
        public void run() {
            InputStream inputStream = System.in;
            OutputStream outputStream = System.out;
            FastInput in = new FastInput(inputStream);
            FastOutput out = new FastOutput(outputStream);
            ECommonNumber solver = new ECommonNumber();
            solver.solve(1, in, out);
            out.close();
        }
    }

    static class ECommonNumber {
        private long[][] dp = new long[62][2];
        private long n;

        public void solve(int testNumber, FastInput in, FastOutput out) {
            long n = in.readLong();
            long m = in.readLong();

            LongBinarySearch lbs1 = new LongBinarySearch() {

                public boolean check(long mid) {
                    mid = mid * 2 + 1;
                    return count(n, mid) < m;
                }
            };
            LongBinarySearch lbs2 = new LongBinarySearch() {

                public boolean check(long mid) {
                    mid = mid * 2;
                    return count(n, mid) + count(n, mid + 1) < m;
                }
            };

            long ans1 = lbs1.binarySearch(1, n / 2);
            if (ans1 == 0) {
                ans1 = -1;
            } else if (lbs1.check(ans1)) {
                ans1 = (ans1 - 1) * 2 + 1;
            } else {
                ans1 = ans1 * 2 + 1;
            }

            long ans2 = lbs2.binarySearch(0, n / 2);
            if (ans2 == 0) {
                ans2 = -1;
            } else if (lbs2.check(ans2)) {
                ans2 = (ans2 - 1) * 2;
            } else {
                ans2 = ans2 * 2;
            }

            long ans = Math.max(ans1, ans2);
            out.println(ans);
        }

        public long dp(int i, int ceil) {
            if (i < 0) {
                return 1;
            }
            if (dp[i][ceil] == -1) {
                int bit = Bits.bitAt(n, i);
                dp[i][ceil] = 0;
                for (int j = 0; j <= 1; j++) {
                    if (ceil == 1 && j > bit) {
                        continue;
                    }
                    dp[i][ceil] += dp(i - 1, ceil == 1 &&
                            bit == j ? 1 : 0);
                }
            }
            return dp[i][ceil];
        }

        public long count(long n, long prefix) {
            if (prefix > n) {
                return 0;
            }
            int len = CachedLog2.floorLog(prefix);
            int totalLen = CachedLog2.floorLog(n);
            long ans = 0;
            for (int i = len; i < totalLen; i++) {
                ans += 1 << (i - len);
            }
            this.n = n;
            SequenceUtils.deepFill(dp, -1L);
            if (prefix > (n >>> (totalLen - len))) {
                return ans;
            }
            int ceil = (prefix == (n >>> (totalLen - len))) ? 1 : 0;
            long plus = dp(totalLen - len - 1, ceil);
            return ans + plus;
        }

    }

    static class SequenceUtils {
        public static void deepFill(Object array, long val) {
            if (!array.getClass().isArray()) {
                throw new IllegalArgumentException();
            }
            if (array instanceof long[]) {
                long[] longArray = (long[]) array;
                Arrays.fill(longArray, val);
            } else {
                Object[] objArray = (Object[]) array;
                for (Object obj : objArray) {
                    deepFill(obj, val);
                }
            }
        }

    }

    static class FastOutput implements AutoCloseable, Closeable, Appendable {
        private StringBuilder cache = new StringBuilder(10 << 20);
        private final Writer os;

        public FastOutput append(CharSequence csq) {
            cache.append(csq);
            return this;
        }

        public FastOutput append(CharSequence csq, int start, int end) {
            cache.append(csq, start, end);
            return this;
        }

        public FastOutput(Writer os) {
            this.os = os;
        }

        public FastOutput(OutputStream os) {
            this(new OutputStreamWriter(os));
        }

        public FastOutput append(char c) {
            cache.append(c);
            return this;
        }

        public FastOutput append(long c) {
            cache.append(c);
            return this;
        }

        public FastOutput println(long c) {
            return append(c).println();
        }

        public FastOutput println() {
            cache.append(System.lineSeparator());
            return this;
        }

        public FastOutput flush() {
            try {
                os.append(cache);
                os.flush();
                cache.setLength(0);
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
            return this;
        }

        public void close() {
            flush();
            try {
                os.close();
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
        }

        public String toString() {
            return cache.toString();
        }

    }

    static class CachedLog2 {
        private static final int BITS = 16;
        private static final int LIMIT = 1 << BITS;
        private static final byte[] CACHE = new byte[LIMIT];

        static {
            int b = 0;
            for (int i = 0; i < LIMIT; i++) {
                while ((1 << (b + 1)) <= i) {
                    b++;
                }
                CACHE[i] = (byte) b;
            }
        }

        public static int floorLog(long x) {
            int ans = 0;
            while (x >= LIMIT) {
                ans += BITS;
                x >>>= BITS;
            }
            return ans + CACHE[(int) x];
        }

    }

    static class FastInput {
        private final InputStream is;
        private byte[] buf = new byte[1 << 20];
        private int bufLen;
        private int bufOffset;
        private int next;

        public FastInput(InputStream is) {
            this.is = is;
        }

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

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

        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;
        }

    }

    static class Bits {
        private Bits() {
        }

        public static int bitAt(long x, int i) {
            return (int) ((x >> i) & 1);
        }

    }

    static abstract class LongBinarySearch {
        public abstract boolean check(long mid);

        public long binarySearch(long l, long r) {
            if (l > r) {
                throw new IllegalArgumentException();
            }
            while (l < r) {
                long mid = (l + r) >>> 1;
                if (check(mid)) {
                    r = mid;
                } else {
                    l = mid + 1;
                }
            }
            return l;
        }

    }
}


// Problem : E. Common Number
// Contest : Codeforces Round #608 (Div. 2)
// URL : https://codeforces.com/contest/1271/problem/E
// Memory Limit : 256.000000MB
// Time Limit : 2000.000000milisec
// Powered by CP Editor (https://github.com/coder3101/cp-editor2)

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

public class a {

  public static void main(String[] args) {
    InputReader in = new InputReader(System.in);
    PrintWriter out = new PrintWriter(System.out);

    Task solver = new Task();
    solver.solve(1, in, out);

    out.close();
  }

  static class Task {

    private long n;
    private long k;

    public void solve(int testNumber, InputReader in, PrintWriter out) {
      n = in.nextInt();
      k = in.nextInt();

      long lo = 1, hi1 = n / 2;
      while (lo <= hi1) {
        long mi = hi1 - (hi1 - lo) / 2;
        if (count (2 * mi) >= k) {
          lo = mi + 1;
        }
        else hi1 = mi - 1;
      }
      lo = 1;
      long hi2 = n / 2;
      while (lo <= hi2) {
        long mi = hi2 - (hi2 - lo) / 2;
        if (count (2 * mi - 1) >= k)
          lo = mi + 1;
        else hi2 = mi - 1;
      }
      hi1 *= 2;
      hi2 = hi2 * 2 - 1;
      if (hi1 == 0)
        hi1 = 1;
      out.println(hi1 > hi2 ? hi1 : hi2);
    }

    private long count(long x) {
      long sol = 0;
      long pow = 1;
      if ((x & 1) == 1 && 2 * x <= n) {
        x *= 2;
        ++sol;
      }
      while (x <= n) {
        long nr = (1 << pow);
        if (x + nr <= n) {
          x *= 2;
          sol += nr;
          ++pow;
        } else {
          sol += n - x + 1;
          break;
        }
      }
      return sol;
    }
  }

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

  }
}


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

	public static void main(String[] args) throws Exception{
		long num = 998244353;

		// TODO Auto-generated method stub
 		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
 		PrintWriter out = new PrintWriter(System.out);
 		StringTokenizer st = new StringTokenizer(bf.readLine());
 		long n = Long.parseLong(st.nextToken());
 		long k = Long.parseLong(st.nextToken());
 		long l = 1;
 		long r = (n+1)/2;
 		while(l < r){
 			long mid = (l+r+1)/2;
 			if (appearFirstN(n, 2*mid) >=k)
 				l = mid;
 			else
 				r = mid-1;
 		}

 		if (n == k)
 			out.println(1);
 		else
 			out.println(appearFirstN(n, 2*l+1) >= k ? 2*l+1 : 2*l);

 		out.close();

 	}
	public static long appearFirstN(long n, long k){
		long ans =0;
		if (k%2 == 0){
			k/=2;
			ans-=1;
		}

		String a = Long.toString(n, 2);
		long prod = 1;
		String b = Long.toString(k, 2);
		if (a.substring(0, b.length()).equals(b)){
			ans+= (Long.parseLong(a.substring(b.length()), 2)+1);
		}
		else if (a.substring(0, b.length()).compareTo(b) > 0){
			prod = 2;
		}

		for(int j =0;j<a.length()-b.length();j++){
			prod*=2L;
		}
		ans+= (prod-1);
		return ans;

	}
}

//StringJoiner sj = new StringJoiner(" ");
//sj.add(strings)
//sj.toString() gives string of those stuff w spaces or whatever that sequence is


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

	public static void main(String[] args) throws Exception{
		long num = 998244353;

		// TODO Auto-generated method stub
 		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
 		PrintWriter out = new PrintWriter(System.out);
 		StringTokenizer st = new StringTokenizer(bf.readLine());
 		long n = Long.parseLong(st.nextToken());
 		long k = Long.parseLong(st.nextToken());
 		long l = 1;
 		long r = (n+1L)/2L;
 		while(l < r){
 			long mid = (l+r+1L)/2L;
 			if (appearFirstN(n, 2L*mid) >=k)
 				l = mid;
 			else
 				r = mid-1;
 		}

 		if (n == k)
 			out.println(1);
 		else
 			out.println(appearFirstN(n, 2L*l+1L) >= k ? 2L*l+1L : 2L*l);

 		out.close();

 	}
	public static long appearFirstN(long n, long k){
		if (k > n)
			return 0;
		long ans =0;
		if (k%2 == 0){
			k/=2;
			ans-=1;
		}

		String a = Long.toString(n, 2);
		long prod = 1;
		String b = Long.toString(k, 2);
		if (a.substring(0, b.length()).equals(b)){
			ans+= (Long.parseLong(a.substring(b.length()), 2)+1);
		}
		else if (a.substring(0, b.length()).compareTo(b) > 0){
			prod = 2;
		}

		for(int j =0;j<a.length()-b.length();j++){
			prod*=2L;
		}
		ans+= (prod-1);
		return ans;

	}
}

//StringJoiner sj = new StringJoiner(" ");
//sj.add(strings)
//sj.toString() gives string of those stuff w spaces or whatever that sequence is


import com.sun.xml.internal.fastinfoset.util.CharArray;

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

public class Main {
    public static void main(String[] args) {

        File file = new File("in.txt");
        File fileOut = new File("out.txt");
        InputStream inputStream = null;
        OutputStream outputStream = null;
        // try {inputStream= new FileInputStream(file);} catch (FileNotFoundException ex){return;};
//        try {outputStream= new FileOutputStream(fileOut);} catch (FileNotFoundException ex){return;};
        inputStream = System.in;
        outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(1, in, out);
        out.close();
    }

}

class Task {

    List<String> lines;
    public void solve(int testNumber, InputReader in, PrintWriter out) {
        lines = new ArrayList<>(9);
        for (int i = 0; i < 3; i++) {
            lines.add(in.nextLine());
        }
        in.nextLine();
        for (int i = 0; i < 3; i++) {
            lines.add(in.nextLine());
        }
        in.nextLine();
        for (int i = 0; i < 3; i++) {
            lines.add(in.nextLine());
        }

        Integer row = (in.nextInt() - 1) % 3;
        Integer col = (in.nextInt() - 1) % 3;

        if (!isFull(row, col)) {
            fill(row, col);
            int counter = 0;
            for (String line : lines) {
                if(counter>0 && counter%3 == 0){
                    out.println();
                }

                out.println(line);
                counter++;
            }
        } else {
            int counter = 0;
            for (String line : lines) {
                if(counter>0 && counter%3 == 0){
                    out.println();
                }

                String s  = line.replace('.', '!');
                out.println(s);
                counter++;
            }

       }
    }

    public void fill(Integer row, Integer col){
        for(int i = row * 3; i < (row+1) * 3; i++){
            char[] ch  = lines.get(i).toCharArray();
            for(int j= col * 3; j < (col+1) * 3; j++){
                if(ch[j] == '.'){
                    ch[j] = '!';
                }
            }
            lines.set(i, new String(ch));
        }

    }
    public Boolean isFull(Integer row, Integer col){
        for(int i = row * 3; i < (row+1) * 3; i++){
            String s  = lines.get(i);
            for(int j= col * 3; j < (col+1) * 3; j++){
                if(s.charAt(j) == '.'){
                    return Boolean.FALSE;
                }

            }
        }
        return Boolean.TRUE;
    }

}

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 String nextLine(){
        try {
            return reader.readLine();
        } catch (IOException e){
            throw new RuntimeException(e);
        }
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }
    public long nextLong() { return Long.parseLong(next()); }

}

class Pair<F, S> {
    public final F first;
    public final S second;

    public Pair(F first, S second) {
        this.first = first;
        this.second = second;
    }

    @Override
    public boolean equals(Object o) {
        if (!(o instanceof Pair)) {
            return false;
        }
        Pair<?, ?> p = (Pair<?, ?>) o;
        return Objects.equals(p.first, first) && Objects.equals(p.second, second);
    }

    @Override
    public int hashCode() {
        return (first == null ? 0 : first.hashCode()) ^ (second == null ? 0 : second.hashCode());
    }

    @Override
    public String toString() {
        return "(" + first + ", " + second + ')';
    }
}

class IntPair extends Pair<Integer, Integer>{
    public IntPair(Integer first, Integer second){
        super(first, second);
    }
}


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
 *
 * @author Abhilash
 */
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);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            TaskB.Node table[][] = new TaskB.Node[3][3];
            for (int i = 0; i < 3; i++) {
                for (int j = 0; j < 3; j++) {
                    table[i][j] = new TaskB.Node();
                }
            }

            for (int i = 0; i < 9; i++) {
                for (int j = 0; j < 3; j++) {
                    String s = in.next();
                    table[i / 3][j].fill(s, i % 3);
                }
            }

            int x = in.nextInt() - 1;
            int y = in.nextInt() - 1;

            int p = x % 3;
            int q = y % 3;

            int count = table[p][q].fill2();

            if (count == 0) {
                for (int i = 0; i < 3; i++) {
                    for (int j = 0; j < 3; j++) {
                        if (i != p || j != q) {
                            table[i][j].fill2();
                        }
                    }
                }
            }

            for (int i = 0; i < 9; i++) {
                for (int j = 0; j < 3; j++) {
                    out.print(table[i / 3][j].sarr[i % 3] + " ");
                }
                out.println();
                if (i % 3 == 2)
                    out.println();
            }
        }

        static class Node {
            char arr = new char[3][3];
            String sarr = new String[3];

            void fill(String s, int idx) {
                for (int i = 0; i < 3; i++) {
                    arr[idx][i] = s.charAt(i);
                }
                sarr[idx] = s;
            }

            int fill2() {
                int count = 0;
                for (int i = 0; i < 3; i++) {
                    for (int j = 0; j < 3; j++) {
                        if (arr[i][j] == '.') {
                            arr[i][j] = '!';
                            count += 1;
                        }
                    }
                    sarr[i] = arr[i][0] + "" + arr[i][1] + arr[i][2];
                }
                return count;
            }

        }

    }

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

    }
}


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

public final class BTicTacToe {

    private void solve(InputReader in, PrintWriter out, int tn) throws IOException {
        char [][] a = new char[9][9];
        for (int i = 0; i < 9; i++) {
            if (i%3==0 && i!=0){
                in.reader.read();
            }
            for (int j = 0; j < 9; j++) {
                if (j % 3 == 0 && j!= 0){
                    in.reader.read();
                }
                a[i][j] = (char) in.reader.read();
            }
            in.reader.read();
        }
        try {
            int si = ((in.nextInt() - 1) % 3) * 3;
        } catch (Exception e) {
            for (int i = 0; i < 9; i++) {
                if (i%3==0 && i!=0){
                    out.println();
                }
                for (int j = 0; j < 9; j++) {
                    if (j % 3 == 0 && j!= 0){
                        out.print(" ");
                    }
                    out.print(a[i][j]);
                }
                out.println();
            }
        }
        try {
            int sj = ((in.nextInt() - 1) % 3) * 3;
        } catch (Exception e) {
            for (int i = 0; i < 9; i++) {
                if (i%3==0 && i!=0){
                    out.println();
                }
                for (int j = 0; j < 9; j++) {
                    if (j % 3 == 0 && j!= 0){
                        out.print(" ");
                    }
                    out.print(a[i][j]);
                }
                out.println();
            }
        }

        /*for (int i = 0; i < 9; i++) {
            for (int j = 0; j < 9; j++) {
                out.print(a[i][j]+" ");
            }
            out.println();
        }
        out.println(si);
        out.println(sj);*/
        int si =4;
        boolean ok = false;
        for (int i = si; i < si+3; i++) {
            for (int j = sj; j < sj+3; j++) {
                if (a[i][j] == '.') {
                    a[i][j] = '!';
                    ok = true;
                }
            }
        }

        if (!ok){
            for (int i = 0; i < 9; i++) {
                for (int j = 0; j < 9; j++) {
                    if (a[i][j] == '.') {
                        a[i][j] = '!';
                    }
                }
            }
        }

        for (int i = 0; i < 9; i++) {
            if (i%3==0 && i!=0){
                out.println();
            }
            for (int j = 0; j < 9; j++) {
                if (j % 3 == 0 && j!= 0){
                    out.print(" ");
                }
                out.print(a[i][j]);
            }
            out.println();
        }
    }

    private int gcd(int x, int y) {
        if (y == 0) {
            return x;
        } else {
            return gcd(y, x % y);
        }
    }

    public static void main(String[] args) throws IOException {
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        new BTicTacToe().solve(in, out, 1);
        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.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
 *
 * @author Abhilash
 */
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);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            TaskB.Node table[][] = new TaskB.Node[3][3];
            for (int i = 0; i < 3; i++) {
                for (int j = 0; j < 3; j++) {
                    table[i][j] = new TaskB.Node();
                }
            }

            for (int i = 0; i < 9; i++) {
                for (int j = 0; j < 3; j++) {
                    String s = in.next();
                    table[i / 3][j].fill(s, i % 3);
                }
            }

            int x = in.nextInt() - 1;
            int y = in.nextInt() - 1;

            int p = x % 3;
            int q = y % 3;

            int count = table[p][q].fill2();

            if (count == 0) {
                for (int i = 0; i < 3; i++) {
                    for (int j = 0; j < 3; j++) {
                        if (i != p || j != q) {
                            table[i][j].fill2();
                        }
                    }
                }
            }

            for (int i = 0; i < 9; i++) {
                for (int j = 0; j < 3; j++) {
                    out.print(table[i / 3][j].sarr[i % 3] + " ");
                }
                out.println();
                if (i % 3 == 2)
                    out.println();
            }
        }

        public static class Node {
            char arr = new char[3][3];
            String sarr = new String[3];

            void fill(String s, int idx) {
                for (int i = 0; i < 3; i++) {
                    arr[idx][i] = s.charAt(i);
                }
                sarr[idx] = s;
            }

            int fill2() {
                int count = 0;
                for (int i = 0; i < 3; i++) {
                    for (int j = 0; j < 3; j++) {
                        if (arr[i][j] == '.') {
                            arr[i][j] = '!';
                            count += 1;
                        }
                    }
                    sarr[i] = arr[i][0] + "" + arr[i][1] + arr[i][2];
                }
                return count;
            }

        }

    }

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

    }
}


import java.util.*;

public class CodeForces
{
	public static void main(String args[])
	{
		Scanner input = new Scanner(System.in);

		int[][] array = new int[101][101];
		int[][] for2type = new int[101][101];
		for (int i = 2; i <= 100; i++)
		{
			for (int j = 2; j <= 100; j++)
			{
				ArrayList<Integer> primes = factors(j);
				ArrayList<Integer> missed = new ArrayList<>();
				boolean check = true;
				for (int k = 0; k < primes.size(); k++)
				{
					if (i % primes.get(k) != 0)
					{
						missed.add(primes.get(k));
						check = false;
					}
				}
				if (check)
				{
					array[i][j] = 2;
					for (int k = 1; k < Integer.MAX_VALUE; k++)
					{
						if (power(i, k) % j == 0)
						{
							for2type[i][j] = k;
							break;
						}
					}
				} else if (i % j == 1)
				{
					array[i][j] = 3;
				} else if ((i + 1) % j == 0)
				{
					array[i][j] = 11;
				} else
				{
					boolean bad = false;
					for (int k = 0; k < primes.size(); k++)
					{
						int num = 0;
						for (int l = 1; l < Integer.MAX_VALUE; l++)
						{
							int z = power(primes.get(k), l);
							if (j % z == 0)
							{
								num = z;
							} else
							{
								break;
							}
						}
						if (array[i][num] == 0 || array[i][num] == 7)
						{
							bad = true;
						}
					}
					if (bad)
					{
						array[i][j] = 7;
					} else
					{
						array[i][j] = 6;
					}
				}
			}
		}

		int b = input.nextInt();
		int d = input.nextInt();
		System.out.println(array[b][d] + "-type");
		if (array[b][d] == 2)
		{
			System.out.println(for2type[b][d]);
		}
	}

	public static ArrayList<Integer> factors(int n)
	{
		ArrayList<Integer> list = new ArrayList<>();
		while (n > 1)
		{
			for (int i = 2; i <= n; i++)
			{
				if (n % i == 0)
				{
					n = n / i;
					if (!list.contains(i))
					{
						list.add(i);
					}
					break;
				}
			}
		}
		return list;
	}

	public static int power(int a, int b)
	{
		int result = 1;
		while (b > 0)
		{
			if (b % 2 != 0)
			{
				result = (result * a);
				b--;
			}
			a = (a * a);
			b /= 2;
		}

		return result;
	}
}


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

import static java.lang.Math.*;

public class Main implements Runnable {

    static String filename = "";

    int[] factorize(int n) {
        ArrayList<Integer> ans = new ArrayList<Integer>();
        for (int i = 2; i <= n; i++) {
            while (n % i == 0) {
                ans.add(i);
                n /= i;
            }
        }
        int[] ansa = new int[ans.size()];
        for (int i = 0; i < ans.size(); i++) {
            ansa[i] = ans.get(i);
        }
        return ansa;
    }

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

    int digitsum(int n, int b) {
        int ans = 0;
        while (n > 0) {
            ans += n % b;
            n /= b;
        }
        return ans;
    }

    int get3(int b) {
        Random rnd = new Random();
        int ans = 0;
        for (int i = 0; i < 10000; i++) {
            int num = rnd.nextInt(1000000000);
            ans = gcd(ans, num - digitsum(num, b));
        }
        return ans;
    }

    int is2type(int b, int d) {
        int[] bfactors = factorize(b);
        int[] dfactors = factorize(d);

        boolean type2 = true;
        TreeMap<Integer, Integer> bf = new TreeMap<Integer, Integer>();
        for (int i : bfactors) {
            if (!bf.containsKey(i)) {
                bf.put(i, 0);
            }
            bf.put(i, bf.get(i) + 1);
        }
        TreeMap<Integer, Integer> df = new TreeMap<Integer, Integer>();
        for (int i : dfactors) {
            if (!df.containsKey(i)) {
                df.put(i, 0);
            }
            df.put(i, df.get(i) + 1);
        }
        for (int i : dfactors) {
            if (!bf.containsKey(i)) {
                type2 = false;
            }
        }

        if (type2) {
            int ans = 0;
            long pow = 1;
            while (pow % d != 0) {
                pow *= b;
                ans++;
                /*
                for (Map.Entry<Integer, Integer> e : df.entrySet()) {
                    System.out.println(e.getKey() + " " + e.getValue());
                }
                System.out.println();
                */
            }
            return ans;
        } else {
            return -1;
        }
    }

    boolean is3type(int b, int d) {
        return (b - 1) % d == 0;
    }

    boolean is11type(int b, int d) {
        return (b + 1) % d == 0;
    }

    HashMap<Integer, Boolean> type6 = new HashMap<Integer, Boolean>();

    boolean is6type(int b, int d) {
        if (type6.containsKey(d)) {
            return type6.get(d);
        }
        for (int i = 2; i < d; i++) {
            if (d % i == 0) {
                int di = d / i;
                if (i % di == 0 || di % i == 0) {
                    continue;
                }
                boolean[] m1 = getMask(b, i);
                boolean[] m2 = getMask(b, di);
                for (int ii = 0; ii < 4; ii++) {
                    for (int jj = 0; jj < 4; jj++) {
                        if (ii == jj) {
                            continue;
                        }
                        if (m1[ii] && m2[jj]) {
                            type6.put(d, true);
                            return true;
                        }
                    }
                }
                /*
                if (is2type(b, i) != -1 || is3type(b, i) || is11type(b, i) || is6type(b, i)) {
                    if (is2type(b, di) != -1 || is3type(b, di) || is11type(b, di) || is6type(b, di)) {
                        if (is3type(b, i) && is3type(b, di))
                            continue;
                        type6.put(d, true);
                        return true;
                    }
                }
                */
            }
        }
        type6.put(d, false);
        return false;
    }

    boolean[] getMask(int b, int d) {
        boolean[] ans = new boolean[4];
        ans[0] = is2type(b, d) != -1;
        ans[1] = is3type(b, d);
        ans[2] = is11type(b, d);
        ans[3] = is6type(b, d);
        return ans;
    }

    public void solve() throws Exception {
        int b = sc.nextInt(), d = sc.nextInt();
        int ans;
        if ((ans = is2type(b, d)) != -1) {
            out.println("2-type");
            out.println(ans);
        } else if (is3type(b, d)) {
            out.println("3-type");
        } else if (is11type(b, d)) {
            out.println("11-type");
        } else if (is6type(b, d)) {
            out.println("6-type");
        } else {
            out.println("7-type");
        }
    }

    BufferedReader in;
    PrintWriter out;
    FastScanner sc;

    public static void main(String[] args) {
        new Thread(null, new Main(), "", 1 << 25).start();
    }

    @Override
    public void run() {
        try {
            init();
            solve();
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            out.close();
        }
    }

    void init() throws Exception {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        sc = new FastScanner(in);
    }
}

class FastScanner {

    BufferedReader reader;
    StringTokenizer strTok;

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

    public String nextToken() throws IOException {
        while (strTok == null || !strTok.hasMoreTokens()) {
            strTok = new StringTokenizer(reader.readLine());
        }

        return strTok.nextToken();
    }

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

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

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

    public BigInteger nextBigInteger() throws IOException {
        return new BigInteger(nextToken());
    }

}


import java.io.*;
import java.util.*;
public class c {
public static void main(String[] args) throws IOException {
	input.init(System.in);
	PrintWriter out = new PrintWriter(System.out);
	int b = input.nextInt(), d = input.nextInt();
	int[] fsb = new int[101], fsd = new int[101];
	int bb = b, dd = d;
	for(int i = 2; i<=100; i++)
	{
		while(bb%i == 0)
		{
			fsb[i]++;
			bb /= i;
		}
		while(dd%i == 0)
		{
			fsd[i]++;
			dd /= i;
		}
	}
	boolean two = true;
	int max = 0;
	for(int i = 2; i<100; i++)
	{
		if(fsd[i] > 0 && fsb[i] == 0) two = false;
		else if(fsd[i] > 0)
		{
			max = Math.max(max, (fsd[i] + fsb[i] - 1)/fsb[i]);
		}
	}
	if(two)
	{
		out.println("2-type");
		out.println(max);
	}
	else if(b%d == 1)
	{
		out.println("3-type");
	}
	else if((b+1)%d == 0)
	{
		out.println("11-type");
	}
	else
	{
		boolean good = true;
		for(int i = 0; i<100; i++)
		{
			if(fsd[i] == 0) continue;
			int pow = 1;
			for(int j = 0; j<fsd[i]; j++) pow *= i;
			good &= fsb[i] > 0 || b%pow == 1 || (b+1)%pow == 0;
		}
		out.println(good ? "6-type" : "7-type");
	}
	out.close();
}

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

	static void init(InputStream input) {
		reader = new BufferedReader(new InputStreamReader(input));
		tokenizer = new StringTokenizer("");
	}

	static String next() throws IOException {
		while (!tokenizer.hasMoreTokens())
			tokenizer = new StringTokenizer(reader.readLine());
		return tokenizer.nextToken();
	}

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

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

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


import java.io.*;
import java.lang.Math;
import java.util.*;

public class Main
{
	public BufferedReader in;
	public PrintStream out;

	public boolean log_enabled = true;

	public int[] calc(int x, int d)
	{
		int[] res = new int[2], res2;

		int dd = d, i;
		for (i=1; i<8; i++)
		{
			if (dd % x == 0)
			{
				res[0] = 2;
				res[1] = i;
				return res;
			}
			dd *= d;
		}

		if (d % x == 1)
		{
			res[0] = 3;
			return res;
		}

		if (d % x == x-1)
		{
			res[0] = 11;
			return res;
		}

		i=2;
		int x0 = x;
		while ((x>1)&&(i<x0))
		{
			if (x % i == 0)
			{
				dd=1;
				while (x % i == 0)
				{
					dd *= i;
					x /= i;
				}

				res2 = calc(dd, d);
				if (res2[0]==7)
				{
					out.printf("%d-7\n", dd);

					res[0] = 7;
					return res;
				}
			}

			i++;
		}

		res[0] = x==1 ? 6 : 7;
		return res;
	}

	public void test()
	{
		int b = readInt();
		int x = readInt();

		int[] res = calc(x, b);

		out.printf("%d-type\n", res[0]);
		if (res[0]==2)
		{
			out.println(res[1]);
		}
	}

	public void run()
	{
		try
		{
			in = new BufferedReader(new InputStreamReader(System.in));
			out = System.out;

			//in = new BufferedReader(new FileReader("in.txt"));
			//out = new PrintStream(new File("out.txt"));

		}
		catch (Exception e)
		{
			return;
		}

		//while (true)
		{
			//int t = readInt(); for (int i=0; i<t; i++)
			{
				test();
			}
		}
	}

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

	private StringTokenizer tokenizer = null;

	public int readInt()
	{
        return Integer.parseInt(readToken());
    }

    public long readLong()
	{
        return Long.parseLong(readToken());
    }

    public double readDouble()
	{
        return Double.parseDouble(readToken());
    }

	public String readLn()
	{
		try
		{
			String s;
			while ((s = in.readLine()).length()==0);
			return s;
		}
		catch (Exception e)
		{
			return "";
		}
	}

    public String readToken()
	{
		try
		{
			while (tokenizer == null || !tokenizer.hasMoreTokens())
			{
				tokenizer = new StringTokenizer(in.readLine());
			}
			return tokenizer.nextToken();
		}
		catch (Exception e)
		{
			return "";
		}
    }

	public int[] readIntArray(int n)
	{
		int[] x = new int[n];
		readIntArray(x, n);
		return x;
	}

	public void readIntArray(int[] x, int n)
	{
		for (int i=0; i<n; i++)
		{
			x[i] = readInt();
		}
	}

	public void logWrite(String format, Object... args)
	{
		if (!log_enabled)
		{
			return;
		}

		out.printf(format, args);
	}
}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Stack;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.StringTokenizer;
import java.util.TreeSet;
public class trial
{
	static BufferedReader reader;
    static StringTokenizer tokenizer;
    static void init(InputStream input)
    {
        reader = new BufferedReader( new InputStreamReader(input) );
        tokenizer = new StringTokenizer("");
    }
    static String next() throws IOException
    {
        while ( ! tokenizer.hasMoreTokens() )
        {
            tokenizer = new StringTokenizer(reader.readLine() );
        }
        return tokenizer.nextToken();
    }

    static long nextInt() throws IOException
    {
        return Long.parseLong( next() );
    }
	static PrintWriter writer;
	static void outit(OutputStream outputStream)
	{
		writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
	}
	static void print(Object...objects) {
		for (int i = 0; i < objects.length; i++)
		{
			if (i != 0)
				writer.print(' ');
			writer.print(objects[i]);
		}
	}

	static void println(Object...objects)
	{
		print(objects);
		writer.println();
	}

	static void close()
	{
		writer.close();
	}

	static void flush() {
		writer.flush();
	}
	public static void print_a(long [] a)
    {
    	for(long i : a)
    	{
    		print(i+" ") ;
    	}
    	println() ;
    }
    public static void main(String [] args) throws IOException
    {
    	init(System.in) ;
    	outit(System.out) ;
//    	int t = (int) nextInt() ;
//    	for(int i =0 ; i<t ; i++)
    	output() ;
        flush();
        close();
    }
    public static void output() throws IOException
    {
    	int n = (int)nextInt() ;
    	int [] ctr = new int[9] ;
    	for(int i = 1 ; i<=n ; i++)
    	{
    		ctr[i%9]++ ;
    	}
    	int [] n_fac = new int[n+1] ;
    	for(int i = 1 ; i<=n ; i++)
    	{
    		for(int j = 1 ; j<=Math.floor(Math.sqrt(i)); j++)
    		{
    			if(i%j==0)
    			{
    				if(j*j==i)
    				{
    					n_fac[i]++ ;
    				}
    				else
    				{
    					n_fac[i]+=2 ;
    				}
    			}
    		}
    	}
    	long ans = 0 ;
    	for(int i = 1 ; i<=n ; i++)
    	{
    		int m = i%9 ;
    		for(int j=0 ; j<9 ; j++)
    		{
    			for(int k = 0; k<9 ; k++)
    			{
    				if(j!=k)
    				{
    					if(((j%9)*(k%9))%9==m)
    					{
    						ans+=ctr[j]*ctr[k];
//    						println(i+" "+j+" "+k) ;
    					}
    				}
    			}
    		}
    		for(int j = 0; j<9 ; j++)
    		{
    			if((j*j)%9==m)
    			{
    				ans+=ctr[j]*ctr[j] ;
    			}
    		}
    		ans-= n_fac[i] ;
    	}
    	println(ans) ;
    }
}


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

public class sol {

    public Scanner in;
    public PrintWriter out;
    public long res;
    public int n, roots[], divs[], prime[], nprime;
    public long byroot[];

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

    public int getRoot(int x) {
        int t = x, tt;
        while (t > 9) {
            tt = 0;
            while (t > 0) {
                tt += t % 10;
                t /= 10;
            }
            t = tt;
        }
        return t;
    }

    public void doPrime() {
        int i, j, erat[] = new int[n + 1];
        prime = new int[n];

        nprime = 1;
        prime[0] = 2;
        for (i = 3; i <= n; i = i + 2) {
            if (erat[i] == 0) {
                prime[nprime] = i;
                nprime++;
                j = i + i;
                while (j <= n) {
                    erat[j] = 1;
                    j += i;
                }
            }
        }
    }

    public void doDivs() {
        int i, j, k, t, p, d;
        divs = new int[n + 1];

        divs[1] = 1;
        for (i = 2; i <= n; i++) {
            d = 1;
            j = 0;
            p = prime[j];
            t = i;
            while (p <= i) {
                k = 0;
                while (t % p == 0) {
                    k++;
                    t /= p;
                }
                if (k > 0) d *= (1 + k);
                j++;
                if (j >= nprime) break;
                p = prime[j];
            }
            divs[i] = d;
        }
    }

    public void run() throws IOException {
        in = new Scanner(System.in);
        out = new PrintWriter(System.out);

        int i, j, k, nn;

        n = in.nextInt();
        nn = n;
        long n2 = n;
        n2 *= n2;
        if (nn < 81) nn = 81;
        byroot = new long[10];
        roots = new int[1000001];
        long byrootx[][] = new long[10][10];
        doPrime();

//      out.println("prime ok");
//      out.flush();

        doDivs();

//      out.println("divs ok");
//      out.flush();

        for (i = 1; i <= nn; i++) {
            roots[i] = getRoot(i);
            if (i <= n) byroot[roots[i]]++;
        }
        for (j = 1; j <= 9; j++)
        for (k = 1; k <= 9; k++)
        byrootx[j][k] = byroot[j] * byroot[k];
        out.flush();
        res = 0;
        for (i = 1; i <= n; i++) {
            for (j = 1; j <= 9; j++)
            for (k = 1; k <= 9; k++)
            if (roots[j * k] == roots[i]) res += byrootx[j][k];
            res -= divs[i];
        }
        out.println(res);

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


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

public class MainC {

    private FastScanner in;
    private PrintWriter out;

    public void solve() throws IOException {
        int N = in.nextInt();
        byte[] digitRoot = new byte[Math.max(N + 1, 100)];
        for (int i = 1; i < digitRoot.length; i++) {
            int s = 0;
            int k = i;
            while (k >= 10) {
                s = s + k % 10;
                k = k / 10;
            }
            s = s + k;
            if (s < 10) {
                digitRoot[i] = (byte) s;
            }
            else {
                digitRoot[i] = digitRoot[s];
            }
        }

        int[] digitRootCount = new int[10];
        for (int i = 1; i <= N; i++) {
            digitRootCount[digitRoot[i]]++;
        }

        BigDecimal countAll = new BigDecimal(0);
        for (int i = 1; i <= 9; i++) {
            for (int j = 1; j <= 9; j++) {
                for (int k = 1; k <= 9; k++) {
                    if (digitRoot[j * k] == i) {
                        long temp = digitRootCount[i];
                        temp *= digitRootCount[j];
                        temp *= digitRootCount[k];
                        // if (temp != 0) {
                        // out.println(i + " " + j + " " + k);
                        // }
                        BigDecimal t = new BigDecimal(temp);
                        countAll = countAll.add(t);
                    }
                }
            }
        }

        long count = 2 * N - 1;
        for (int i = 1; i <= N; i++) {
            int j = 2;
            while (j * j <= i) {
                if (i % j == 0) {
                    if (j * j == i) {
                        count++;
                    }
                    else {
                        count = count + 2;
                    }
                }
                j = j + 1;
            }
        }

        out.println(countAll.subtract(new BigDecimal(count)));
    }

    public void run() {
        try {
            in = new FastScanner(System.in);
            out = new PrintWriter(System.out);
            solve();
            out.close();
        }
        catch (IOException e) {
            e.printStackTrace();
        }
    }

    class FastScanner {

        BufferedReader br;
        StringTokenizer st;

        FastScanner(InputStream is) {
            br = new BufferedReader(new InputStreamReader(is));
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                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());
        }
    }

    public static void main(String[] arg) {
        new MainC().run();
    }
}


import java.io.*;

/**
 * Created by James on 1/29/2015.
 */

public class Driver {
    public static void main(String [] args) throws IOException {
        BufferedReader scanner = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);

        int N = Integer.parseInt(scanner.readLine().trim()), count = 0;

        for (int i = 1; i <= N; ++i) {
            for (int j = 1; j <= N; ++j) {
                for (int k = 1; k <= N; ++k) {
                    if (d(d(i) * d(j)) == d(k) && i * j != k) {
                        //out.println(i + " " + j + " " + k);
                        count++;
                    }
                }
            }
        }

        out.println(count);
        out.close();
    }

    private static int d(int N) {
        if (N < 10) {
            return N;
        }

        String num = Integer.toString(N);
        int sum = 0;

        for (int i = 0; i < num.length(); ++i) {
            sum += Integer.parseInt(String.valueOf(num.charAt(i)));
        }

        return d(sum);
    }
}