#include #include using namespace std; typedef long double LD; #define N 20 + 5 #define eps 1e-11 const int Fx[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}}; int n, m, k, Go[N][N][2]; char s[N][N]; LD ans, ret = 1.0, Dp[2][N][N]; int main() { scanf("%d%d%d", &n, &m, &k); for (int i = 1; i <= n; i ++) scanf("%s", s[i] + 1); for (int i = 1, x_1, y_1, x_2, y_2; i <= k; i ++) { scanf("%d%d%d%d", &x_1, &y_1, &x_2, &y_2); Go[x_1][y_1][0] = x_2, Go[x_1][y_1][1] = y_2; Go[x_2][y_2][0] = x_1, Go[x_2][y_2][1] = y_1; } for (int i = 1; i <= n; i ++) for (int j = 1; j <= m; j ++) Dp[0][i][j] = (s[i][j] == 'A' ? 1.0 : 0.0); for (int T = 30000000 / (n * m); T && (ret > 5e-7); T --) { for (int i = 1; i <= n; i ++) for (int j = 1; j <= m; j ++) { if (Dp[0][i][j] < eps || s[i][j] == '*') { ret -= Dp[0][i][j]; continue ; } if (s[i][j] == '%') { ans += Dp[0][i][j]; ret -= Dp[0][i][j]; continue ; } int cnt = 0; for (int d = 0; d < 4; d ++) { int x = i + Fx[d][0], y = j + Fx[d][1]; if (x && y && x <= n && y <= m && s[x][y] != '#') cnt ++; } if (!cnt) continue ; for (int d = 0; d < 4; d ++) { int x = i + Fx[d][0], y = j + Fx[d][1]; if (x && y && x <= n && y <= m && s[x][y] != '#') { int _x = x, _y = y; if (Go[_x][_y][0]) x = Go[_x][_y][0], y = Go[_x][_y][1]; Dp[1][x][y] += Dp[0][i][j] / cnt; } } } for (int i = 1; i <= n; i ++) for (int j = 1; j <= m; j ++) Dp[0][i][j] = Dp[1][i][j], Dp[1][i][j] = 0.0; } printf("%.6f\n", (double) ans); return 0; }