1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#include <bits/stdc++.h>

#define ll long long
#define ld long double
#define mp make_pair
#define fi first
#define se second
#define pii pair <int,int>
#define pli pair <ll,int>
#define pll pair <ll,ll>
#define ppi pair <pii,pii>
#define vi vector <int>
#define vl vector <ll>
#define uset unordered_set
#define umap unordered_map
#define INF (1<<30)
#define INF_LL (1ll<<60)
#define MAX 2000005
#define MAX_LVL 21

using namespace std;


template <typename T>
ostream & operator << (ostream &out, const vector <T> &V);

template <typename T>
ostream & operator << (ostream &out, const set <T> &S);

template <typename T>
ostream & operator << (ostream &out, const multiset <T> &S);

template <typename T1, typename T2>
ostream & operator << (ostream &out, const pair <T1, T2> &P);

template <typename T1, typename T2>
ostream & operator << (ostream &out, const map <T1, T2> &M);



void testcase() {
	int n, m, k;
	cin >> n >> m >> k;
	vector <string> V(n);
	for (int i = 0; i < n; i++) {
		cin >> V[i];
	}
	
	// BFS
	vector < vector <int> > D(n, vector <int> (m, -1));
	vector <pii> Mv = {{0,1}, {0,-1}, {-1,0}, {1,0}};
	queue <pii> Q;
	D[0][0] = 0;
	Q.push({0,0});
	while (!Q.empty()) {
		pii r = Q.front();
		Q.pop();
		for (pii &mv : Mv) {
			int row = r.fi + mv.fi, col = r.se + mv.se;
			if (0 <= row && row < n && 0 <= col && col < m && \
				V[row][col] == '.' && D[row][col] == -1) {
					
				D[row][col] = D[r.fi][r.se]  + 1;
				Q.push({row, col});
			}
		}
	}
	
	int to_higher = (n-1) + (m-1), to_lower = (D[n-1][m-1] - to_higher) / 2;
	to_higher += to_lower;
	
	map <ll,int> M;
	for (int i = 0; i < k; i++) {
		ll a, b;
		cin >> a >> b;
		M[to_higher * a + to_lower * b]++;
	}
	auto ans = *M.begin();
	cout << ans.fi << " " << ans.se <<endl;
}

void init() {
    
}

int main() {
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    init();
    int T = 1;
    //cin >> T;
    for (int t = 1; t <= T; t++) {
        testcase();
    }
    return 0;
}




template <typename T>
ostream & operator << (ostream &out, const vector <T> &V) {
	if (!V.empty()) {
		out << "{";
		for (auto v : V)
			out << v << ", ";
		out << "\b\b}";			// \b is backspace
	}
	else {
		out << "{}";
	}
	return out;
}

template <typename T>
ostream & operator << (ostream &out, const set <T> &S) {
	if (!S.empty()) {
		out << "set{";
		for (auto v : S)
			out << v << ", ";
		out << "\b\b}";			// \b is backspace
	}
	else {
		out << "{}";
	}
	return out;
}

template <typename T>
ostream & operator << (ostream &out, const multiset <T> &S) {
	if (!S.empty()) {
		out << "set{";
		for (auto v : S)
			out << v << ", ";
		out << "\b\b}";			// \b is backspace
	}
	else {
		out << "{}";
	}
	return out;
}

template <typename T1, typename T2>
ostream & operator << (ostream &out, const map <T1,T2> &M) {
	if (!M.empty()) {
		out << "map{";
		for (auto &kv : M)
			out << "(" << kv.fi << ": " << kv.se << ")" << ", ";
		out << "\b\b}";			// \b is backspace
	}
	else {
		out << "{}";
	}
	return out;
}

template <typename T1, typename T2>
ostream & operator << (ostream &out, const pair <T1, T2> &P) {
	out << "{" << P.first << ", " << P.second << "}";
	return out;
}