#include <bits/stdc++.h>
using namespace std;
int v[1002][1002];
char s[1002][1002];
int main() {
  int n, m, k;
  cin >> n >> m >> k;
  int l, u;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> s[i][j];
      if (s[i][j] == 'S') {
        l = i;
        u = j;
      }
    }
  }
  cout << "FFF" << '\n';
  queue<pair<int, int> > q;
  q.push(make_pair(l, u));
  cout << l << " " << u << '\n';
  v[l][u] = 1;
  while (!q.empty()) {
    pair<int, int> h = q.front();
    q.pop();
    int i = h.first;
    int j = h.second;
    cout << i << " " << j << '\n';
    if (i + 1 <= n && v[i + 1][j] == 0 && s[i + 1][j] == '.') {
      q.push(make_pair(i + 1, j));
      v[i + 1][j] = 1 + v[i][j];
    }
    if (i - 1 >= 1 && v[i - 1][j] == 0 && s[i - 1][j] == '.') {
      q.push(make_pair(i - 1, j));
      v[i - 1][j] = v[i][j] + 1;
    }
    if (j + 1 <= m && v[i][j + 1] == 0 && s[i][j + 1] == '.') {
      q.push(make_pair(i, j + 1));
      v[i][j + 1] = v[i][j] + 1;
    }
    if (j - 1 >= 1 && v[i][j - 1] == 0 && s[i][j - 1] == '.') {
      q.push(make_pair(i, j - 1));
      v[i][j - 1] = v[i][j] + 1;
    }
  }
  int ans = 100000000;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (v[i][j] == 0) continue;
      int d = v[i][j] - 1;
      int g = min(i - 1, j - 1);
      g = min(n - i, g);
      g = min(m - j, g);
      int f = max(d - k, 0);
      g += f;
      f = g / k;
      if (g % k != 0) f++;
      if (i != n && i != 1 && j != 1 && j != m) f++;
      ans = min(ans, f);
    }
  }
  cout << ans << '\n';
}
