#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > start;
int H, W, K;
int d[1000][1000];
string S[1000];
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
void bfs(int sx, int sy) {
  queue<pair<int, int> > que;
  for (int i = 0; i < H; i++)
    for (int j = 0; j < W; j++) d[i][j] = 2000000000;
  que.push(pair<int, int>(sx, sy));
  d[sx][sy] = 0;
  while (que.size()) {
    pair<int, int> p = que.front();
    que.pop();
    if (p.first == 0 || p.first == H - 1 || p.second == 0 || p.second == W - 1)
      break;
    for (int i = 0; i < 4; i++) {
      int nx = p.first + dx[i], ny = p.second + dy[i];
      if (S[nx][ny] == '.' && d[nx][ny] == 2000000000) {
        que.push(pair<int, int>(nx, ny));
        d[nx][ny] = d[p.first][p.second] + 1;
      }
    }
  }
}
int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> H >> W >> K;
  for (int i = 0; i < H; i++) cin >> S[i];
  int sx, sy;
  for (int i = 0; i < H; i++) {
    bool b = false;
    for (int j = 0; j < W; j++) {
      if (S[i][j] == 'S') {
        sx = i;
        sy = j;
        b = true;
      }
      if (b) break;
    }
    if (b) break;
  }
  bfs(sx, sy);
  int ans = 2000000000;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (d[i][j] <= K) {
        int x = i + 1;
        int y = j + 1;
        cout << x << " " << y << endl;
        ans = min(ans, (min({x, y, H - x, W - y}) + K - 1) / K + 1);
      }
    }
  }
  cout << ans << endl;
  return 0;
}
