Takahashi is locked within a building.

This building consists of H×W rooms, arranged in H rows and W columns. We will denote the room at the i-th row and j-th column as (i,j). The state of this room is represented by a character A_{i,j}. If A_{i,j}= `#`, the room is locked and cannot be entered; if A_{i,j}= `.`, the room is not locked and can be freely entered. Takahashi is currently at the room where A_{i,j}= `S`, which can also be freely entered.

Each room in the 1-st row, 1-st column, H-th row or W-th column, has an exit. Each of the other rooms (i,j) is connected to four rooms: (i-1,j), (i+1,j), (i,j-1) and (i,j+1).

Takahashi will use his magic to get out of the building. In one cast, he can do the following:

* Move to an adjacent room at most K times, possibly zero. Here, locked rooms cannot be entered.
* Then, select and unlock at most K locked rooms, possibly zero. Those rooms will remain unlocked from then on.



His objective is to reach a room with an exit. Find the minimum necessary number of casts to do so.

It is guaranteed that Takahashi is initially at a room without an exit.

Constraints

* 3 ≤ H ≤ 800
* 3 ≤ W ≤ 800
* 1 ≤ K ≤ H×W
* Each A_{i,j} is `#` , `.` or `S`.
* There uniquely exists (i,j) such that A_{i,j}= `S`, and it satisfies 2 ≤ i ≤ H-1 and 2 ≤ j ≤ W-1.

Input

Input is given from Standard Input in the following format:


H W K
A_{1,1}A_{1,2}...A_{1,W}
:
A_{H,1}A_{H,2}...A_{H,W}


Output

Print the minimum necessary number of casts.

Examples

Input

3 3 3
#.#
#S.
###


Output

1


Input

3 3 3
.#
S.


Output

1


Input

3 3 3

S#


Output

2


Input

7 7 2


...##
S###
.#.##
.###


Output

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

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

    static class TaskC {
        static final int INF = (int) 1e9;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int rows = in.nextInt();
            int cols = in.nextInt();
            int k = in.nextInt();
            String[] field = new String[rows];
            int srow = -1;
            int scol = -1;
            for (int row = 0; row < rows; ++row) {
                field[row] = in.next();
                for (int col = 0; col < cols; ++col) {
                    if (field[row].charAt(col) == 'S') {
                        if (srow >= 0) throw new RuntimeException();
                        srow = row;
                        scol = col;
                    }
                }
            }
            if (srow < 0) throw new RuntimeException();
            int[][] best = new int[rows][cols];
            for (int[] x : best) Arrays.fill(x, INF);
            best[srow][scol] = 0;
            int[] qr = new int[rows * cols];
            int[] qc = new int[rows * cols];
            int qt = 0;
            int qh = 1;
            qr[0] = srow;
            qc[0] = scol;
            while (qt < qh) {
                int r = qr[qt];
                int c = qc[qt];
                ++qt;
                for (int dr = -1; dr <= 1; ++dr) {
                    for (int dc = -1; dc <= 1; ++dc) {
                        if (Math.abs(dr) + Math.abs(dc) == 1) {
                            int nr = r + dr;
                            int nc = c + dc;
                            if (field[nr].charAt(nc) == '#' || best[nr][nc] < INF) continue;
                            best[nr][nc] = best[r][c] + 1;
                            if (nr == 0 || nr == rows - 1 || nc == 0 || nc == cols - 1) {
                                out.println(1);
                                return;
                            }
                            if (best[nr][nc] < k) {
                                qr[qh] = nr;
                                qc[qh] = nc;
                                ++qh;
                            }
                        }
                    }
                }
            }
            qh = 0;
            qt = 0;
            for (int r = 0; r < rows; ++r) {
                for (int c = 0; c < cols; ++c) {
                    if (best[r][c] < INF) {
                        best[r][c] = 0;
                        qr[qh] = r;
                        qc[qh] = c;
                        ++qh;
                    }
                }
            }
            while (qt < qh) {
                int r = qr[qt];
                int c = qc[qt];
                ++qt;
                for (int dr = -1; dr <= 1; ++dr) {
                    for (int dc = -1; dc <= 1; ++dc) {
                        if (Math.abs(dr) + Math.abs(dc) == 1) {
                            int nr = r + dr;
                            int nc = c + dc;
                            if (best[nr][nc] < INF) continue;
                            best[nr][nc] = best[r][c] + 1;
                            if (nr == 0 || nr == rows - 1 || nc == 0 || nc == cols - 1) {
                                out.println(1 + (best[nr][nc] + k - 1) / k);
                                return;
                            }
                            qr[qh] = nr;
                            qc[qh] = nc;
                            ++qh;
                        }
                    }
                }
            }
            throw new RuntimeException();
        }

    }

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

    }
}

