#!/bin/python3 import sys sys.setrecursionlimit(50000) n, m, k = [int(x) for x in input().strip().split(' ')] maze = [] ai = -1 aj = -1 for i in range(n): row = input().strip() maze.append(row) if row.find('A') != -1: ai, aj = (i, row.index('A')) tunnels = {} for _ in range(k): i1, j1, i2, j2 = [int(x) for x in input().strip().split(' ')] tunnels[(i1, j1)] = (i2, j2) tunnels[(i2, j2)] = (i1, j1) def get(i, j): return maze[i][j] def getNeighbours(i, j): neigh = [] if i != 0: if get(i-1, j) != '#' and (i-1, j) not in explored: if (i-1, j) in tunnels: neigh.append(tunnels[(i-1, j)]) else: neigh.append((i-1, j)) if i != n-1: if get(i+1, j) != '#' and (i+1, j) not in explored: if (i+1, j) in tunnels: neigh.append(tunnels[(i+1, j)]) else: neigh.append((i+1, j)) if j != 0: if get(i, j-1) != '#' and (i, j-1) not in explored: if (i, j-1) in tunnels: neigh.append(tunnels[(i, j-1)]) else: neigh.append((i, j-1)) if j != m-1: if get(i, j+1) != '#' and (i, j+1) not in explored: if (i, j+1) in tunnels: neigh.append(tunnels[(i, j+1)]) else: neigh.append((i, j+1)) return neigh explored = {} outcomes = [] def getProb(i, j): global outcomes symbol = get(i, j) if symbol == '#' or symbol == '*': outcomes.append(0) return 0 if symbol == '%': outcomes.append(1) return 1 global explored explored[(i, j)] = True neighbours = getNeighbours(i, j) for ni, nj in neighbours: if (ni, nj) not in explored: getProb(ni, nj) getProb(ai, aj) print(sum(outcomes)/len(outcomes))