#include using namespace std; #define int long long #define stoi stoll using ll=long long; using vi=vector; using pii=pair; #define ALL(c) begin(c),end(c) #define RALL(c) rbegin(c),rend(c) #define ITR(i,b,e) for(auto i=(b);i!=(e);++i) #define FORE(x,c) for(auto &x:c) #define REPF(i,a,n) for(int i=a,i##len=(int)(n);i=0;--i) #define SZ(c) ((int)c.size()) #define CONTAIN(c,x) (c.find(x)!=end(c)) #define OUTOFRANGE(y,x,h,w) ((y)<0||(x)<0||(y)>=(h)||(x)>=(w)) #define dump(...) const signed INF_=1001001001; const ll INF=1001001001001001001LL; const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0}; template ostream& operator<<(ostream &os,const vector &v) { ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;} template istream& operator>>(istream &is,vector &v) { ITR(i,begin(v),end(v)) is>>*i;return is;} template istream& operator>>(istream &is, pair &p) { is>>p.first>>p.second;return is;} template bool chmax(T &a,const T &b){if(a bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;} template using heap=priority_queue,greater>; struct{template operator T(){T x;cin>>x;return x;}} IN; struct before_main_function { before_main_function() { cin.tie(0);ios::sync_with_stdio(false); cout< void resize_matrix(vector> &A, int h, int w, T fill) { A.resize(h); for (int i = 0; i < h; i++) { A[i].resize(w, fill); } } template vector> multiple_matrix(vector> &A, vector> &B, function add = [](T a, T b){return a + b;}, function mul = [](T a, T b){return a * b;}, T zero = 0) { int m = A.size(); int n = A[0].size(); assert(n == B.size()); int l = B[0].size(); vector> res; resize_matrix(res, m, l, zero); for (int i = 0; i < m; i++) { for (int j = 0; j < l; j++) { T tmp = 0; for (int k = 0; k < n; k++) { T p = mul(A[i][k], B[k][j]); tmp = add(tmp, p); } res[i][j] = tmp; } } return res; } template vector> pow_matrix(vector> A, int k, function add = [](T a, T b){return a + b;}, function mul = [](T a, T b){return a * b;}, T e = 1, T zero = 0) { int n = A.size(); assert(n == A[0].size()); vector> res; resize_matrix(res, n, n, zero); for (int i = 0; i < n; i++) res[i][i] = e; while (k > 0) { if (k & 1) res = multiple_matrix(res, A, add, mul, zero); A = multiple_matrix(A, A, add, mul, zero); k >>= 1; } return res; } signed main() { int R,C,T; cin>>R>>C>>T; int sy,sx,gy,gx; cin>>sy>>sx>>gy>>gx; vector S(R); cin>>S; vector> Q(R*C,vector(C*R,0)); REP(i,R) { REP(j,C) { if(S[i][j]=='#') continue; int pos=i*C+j; int c=0; REP(d,4) { int ii=i+DY[d]; int jj=j+DX[d]; if(OUTOFRANGE(ii,jj,R,C)) continue; if(S[ii][jj]=='.') c++; } REP(d,4) { int ii=i+DY[d]; int jj=j+DX[d]; int next=ii*C+jj; if(OUTOFRANGE(ii,jj,R,C)) continue; if(S[ii][jj]=='.' && c>0) Q[pos][next]+=1.0/c; } if(c==0) { Q[pos][pos]+=1; } } } Q=pow_matrix(Q, T); int s=sy*C+sx; int g=gy*C+gx; cout<