#include <iostream>
#include<queue>
#include<cstring>
using namespace std;
struct node{
int x,y;
node(int x = 0,int y = 0){
this -> x = x;
this -> y = y;
}
};
queue<node> A;
int n,m,t;
int xx,yy;
char a[8][8];
int d[8][8];
void input(){
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++)
{
cin >> a[i][j];
if(a[i][j]=='S') {
xx = i;
yy = j;
}
}
}
int main()
{
while(cin >> n >> m >> t && (n||m||t)){
input();
memset(d,-1,sizeof(d));
int flag = 0;
int firstnum=0,lastnum=0;
node s(xx,yy);
A.push(s);
firstnum++;
for(int i = 0; i <= t;i++){
while(firstnum){
node noden(A.front().x,A.front().y);
if(i==t){
if(a[noden.x][noden.y]=='D') {
flag = 1;
break;
}
}
A.pop();
firstnum--;
if(noden.x-1>0&&a[noden.x-1][noden.y]=='.'&&d[noden.x-1][noden.y] < i) {
d[noden.x-1][noden.y] = i;
node sn(noden.x-1,noden.y);
cout << noden.x-1 << noden.y <<" ";
A.push(sn);
lastnum++;
}
if(noden.x+1<=n&&a[noden.x+1][noden.y]=='.'&&d[noden.x+1][noden.y] <i) {
d[noden.x+1][noden.y] = i;
node sn(noden.x+1,noden.y);
cout << noden.x+1 << noden.y<<" ";
A.push(sn);
lastnum++;
}
if(noden.y-1>0&&a[noden.x][noden.y-1]=='.'&&d[noden.x][noden.y-1] < i) {
d[noden.x][noden.y-1] = i;
node sn(noden.x,noden.y-1);
cout << noden.x << noden.y-1 <<" ";
A.push(sn);
lastnum++;
}
if(noden.y+1<=m&&a[noden.x][noden.y+1]=='.'&&d[noden.x][noden.y+1] < i) {
d[noden.x][noden.y+1] = i;
node sn(noden.x,noden.y+1);
cout << noden.x << noden.y+1 <<" ";
A.push(sn);
lastnum++;
}
}
cout << endl;
firstnum = lastnum;
lastnum = 0;
}
if(flag) cout <<"YES"<<endl;
else cout << "NO" << endl;
}
return 0;
}