#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
pair<int, int> q[N * N];
char s[N];
int dis[N][N], mx[4] = {0, 0, 1, -1}, my[4] = {1, -1, 0, 0};
bool g[N][N];
int up(int a, int b) { return a % b ? a / b + 1 : a / b; }
int main() {
  int h, w, k;
  scanf("%d%d%d", &h, &w, &k);
  int tx, ty;
  for (int i = 1; i <= h; i++) {
    scanf("%s", s + 1);
    for (int j = 1; j <= w; j++) {
      if (s[j] == '.')
        g[i][j] = 1;
      else if (s[j] == 'S')
        tx = i, ty = j;
    }
  }
  memset(dis, -1, sizeof(dis));
  int he = 0, ta = 0;
  q[++ta] = make_pair(tx, ty), dis[tx][ty] = 0;
  while (he != ta) {
    he++;
    int x = q[he].first, y = q[he].second;
    if (dis[x][y] == k) continue;
    for (int i = 0; i <= 3; i++)
      if (g[x + mx[i]][y + my[i]] && dis[x + mx[i]][y + my[i]] == -1) {
        dis[x + mx[i]][y + my[i]] = dis[x][y] + 1;
        q[++ta] = make_pair(x + mx[i], y + my[i]);
      }
  }
  int ans = 1e9;
  for (int i = 1; i <= h; i++)
    for (int j = 1; j <= w; j++)
      if (dis[i][j] != -1) {
        printf("%d %d\n", i, j);
        ans = min(ans, up(min(i - 1, h - i), k));
        ans = min(ans, up(min(j - 1, w - j), k));
      }
  printf("%d\n", ans + 1);
  return 0;
}
