#include <iostream>
#include <queue>
using namespace std;
#define N 7
bool mark[N][N];
char maze[N][N];
int go[4][2] =
{
-1,0,
1,0,
0,-1,
0,1,
};
int n, m, T, sx, sy, dx, dy, t;
int flag = 0;
void dfs(int x, int y,int t);
int main()
{
while (cin >> m >> n >> T&&m!=0)
{
t = 0;
for (int i = 1; i <= m; i++)
{
for (int j = 1; j <= n; j++)
{
cin >> maze[i][j];
if (maze[i][j] == 'S')
{
sx = i;
sy = j;
}
if (maze[i][j] == 'D')
{
dx = i;
dy = j;
}
mark[i][j] = false;
}
}
dfs(sx, sy,0);
if (flag == 1)
{
cout << "YES" << endl;
}
else
cout << "NO" << endl;
}
system("pause");
return 0;
}
void dfs(int x, int y,int t)
{
mark[x][y] = true;
if (maze[x][y] == 'D'&&t == T)
{
flag = 1;
return;
}
for (int i = 0; i < 4; i++)
{
int nx = x + go[i][0];
int ny = y + go[i][1];
int nt = t + 1;
if (nx<0 || nx>m || ny<0 || ny>n)
continue;
if (mark[nx][ny] == true)
continue;
if (maze[nx][ny] == 'X')
continue;
if (nt > T)
continue;
dfs(nx, ny, nt);
}
return;
}