#include <bits/stdc++.h>
using namespace std;
const int maxn = 801;
short dp[maxn][maxn][401];
int n, m, k;
char table[maxn][maxn];
int r, c;
int ic[4] = {0, 0, -1, 1};
int jc[4] = {1, -1, 0, 0};
short calc(int a, int b, int c) {
  if (c < 0) return 30000;
  if (a == 1 || a == n || b == 1 || b == m) return 0;
  if (dp[a][b][c]) return dp[a][b][c];
  dp[a][b][c] = 30000;
  for (int i = 0; i < 4; i++) {
    int na = a + ic[i], nb = b + jc[i];
    if (table[na][nb] == '#') {
      dp[a][b][c] = min(dp[a][b][c], calc(na, na, c - 1));
    } else {
      dp[a][b][c] = min(dp[a][b][c], calc(na, nb, c));
    }
  }
  dp[a][b][c]++;
  return dp[a][b][c];
}
int32_t main() {
  cin >> n >> m >> k;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> table[i][j];
      if (table[i][j] == 'S') {
        r = i, c = j;
      }
    }
  }
  short ans = 30000;
  for (int i = 0; i <= min(k, 400); i++) {
    int mid = calc(r, c, i);
    cout << i << ' ' << mid << endl;
    ans = min(ans, (short)(mid / k + (mid % k != 0) + (i / k) + (i % k != 0)));
  }
  cout << ans << endl;
}
