def space_input(p=''):
s=raw_input(p).split()
for i in range(len(s)):
s[i]=eval(s[i])
return tuple(s)
class Mymap:
def __init__(self,h,w):
self.sx=self.sy=0
self.height=h
self.width=w
self.allmoves=set()
self.maze=[[' ' for i in range(w)] for i in range(h)]
def getmap(self):
for i in range(self.height):
line=raw_input()
for j in range(self.width):
self.maze[i][j]=line[j]
if line[j]=='S':
self.sx,self.sy=i,j
def move(self,maze,sx,sy,moves=0):
if maze[sx][sy]=='D':
self.allmoves.add(moves)
else:
new=eval(repr(maze))
new[sx][sy]='X'
for i,j in [(sx-1,sy),(sx+1,sy),(sx,sy-1),(sx,sy+1)]:
if 0<=i<self.height and 0<=j<self.width and new[i][j]!='X':
self.move(new,i,j,moves+1)
h,w,t=space_input()
while h or w or t:
a=Mymap(h,w)
a.getmap()
a.move(a.maze,a.sx,a.sy)
if t in a.allmoves:
print 'YES'
else:
print 'NO'
h,w,t=space_input()
/**************************************************************
Problem: 2228
User: admin
Language: Python
Result: Wrong Answer
****************************************************************/