h,w=map(int,input().split()) u,d,r,l,k,p=map(int,input().split()) sx,sy,gx,gy=map(int,input().split()) c=[] for i in range(h): c.append(input()) dxdy=[(-1,0,u),(1,0,d),(0,1,r),(0,-1,l)] #ダイクストラ法 from heapq import heappush, heappop INF=10**18 def dijkstra(sx,sy,h,w): dist = [[INF]*w for i in range(h)] hq=[(0,sx-1,sy-1)] # (distance, node) dist[sx-1][sy-1]=0 seen=[[False]*w for i in range(h)] while hq: a,x,y=heappop(hq) # ノードを pop する # 変更箇所 if seen[x][y]: continue seen[x][y]=True for dx,dy,cost in dxdy: if 0<=x+dx