#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
using namespace std;
#define N 7
char a[N][N];
int b[N][N] = { 0 };
int n, m, t;
int sx, sy, ex, ey;
int mark;
bool jus(int sx,int sy,int ex,int ey) //剪枝
{
int tt = t-abs(sx - ex) + abs(sy - ey);
if (tt < 0 || tt % 2 == 1) return false;
else return true;
}
void dfs(int x, int y,int t)
{
if (mark || t < 0) return;
if (x == ex&&y == ey&&t == 0)
{
mark = 1;
return;
}
if (x < 0 || x >= n || y < 0 || y >= m || a[x][y] == 'X'||b[x][y]) return;
b[x][y] = 1;
dfs(x + 1, y, t - 1);
dfs(x - 1, y, t - 1);
dfs(x, y + 1, t - 1);
dfs(x, y - 1, t - 1);
b[x][y] = 0;
}
int main()
{
while (cin >> n >> m >> t, n, m, t)
{
mark = 0;
for(int i=0;i<n;i++)
for (int j = 0; j < m; j++)
{
cin >> a[i][j];
if (a[i][j] == 'S')
{
sx = i;
sy = j;
a[i][j] = '.';
}
else if (a[i][j] == 'D')
{
ex = i;
ey = j;
}
}
bool x=jus(sx,sy, ex, ey);
if (x)
{
dfs(sx, sy, t);
if (mark) cout << "YES" << endl;
else x = false;
}
if(!x) cout << "NO" << endl;
}
}
#include <cstring>
#include <string>
#include <cstdio>
using namespace std;
#define N 7
char a[N][N];
int b[N][N] = { 0 };
int n, m, t;
int sx, sy, ex, ey;
int mark;
bool jus(int sx,int sy,int ex,int ey) //剪枝
{
int tt = t-abs(sx - ex) + abs(sy - ey);
if (tt < 0 || tt % 2 == 1) return false;
else return true;
}
void dfs(int x, int y,int t)
{
if (mark || t < 0) return;
if (x == ex&&y == ey&&t == 0)
{
mark = 1;
return;
}
if (x < 0 || x >= n || y < 0 || y >= m || a[x][y] == 'X'||b[x][y]) return;
b[x][y] = 1;
dfs(x + 1, y, t - 1);
dfs(x - 1, y, t - 1);
dfs(x, y + 1, t - 1);
dfs(x, y - 1, t - 1);
b[x][y] = 0;
}
int main()
{
while (cin >> n >> m >> t, n, m, t)
{
mark = 0;
for(int i=0;i<n;i++)
for (int j = 0; j < m; j++)
{
cin >> a[i][j];
if (a[i][j] == 'S')
{
sx = i;
sy = j;
a[i][j] = '.';
}
else if (a[i][j] == 'D')
{
ex = i;
ey = j;
}
}
bool x=jus(sx,sy, ex, ey);
if (x)
{
dfs(sx, sy, t);
if (mark) cout << "YES" << endl;
else x = false;
}
if(!x) cout << "NO" << endl;
}
}