Vasya has a very beautiful country garden that can be represented as an n × m rectangular field divided into n·m squares. One beautiful day Vasya remembered that he needs to pave roads between k important squares that contain buildings. To pave a road, he can cover some squares of his garden with concrete.

For each garden square we know number aij that represents the number of flowers that grow in the square with coordinates (i, j). When a square is covered with concrete, all flowers that grow in the square die.

Vasya wants to cover some squares with concrete so that the following conditions were fulfilled: 

  * all k important squares should necessarily be covered with concrete 
  * from each important square there should be a way to any other important square. The way should go be paved with concrete-covered squares considering that neighboring squares are squares that have a common side 
  * the total number of dead plants should be minimum 



As Vasya has a rather large garden, he asks you to help him.

Input

The first input line contains three integers n, m and k (1 ≤ n, m ≤ 100, n·m ≤ 200, 1 ≤ k ≤ min(n·m, 7)) — the garden's sizes and the number of the important squares. Each of the next n lines contains m numbers aij (1 ≤ aij ≤ 1000) — the numbers of flowers in the squares. Next k lines contain coordinates of important squares written as "x y" (without quotes) (1 ≤ x ≤ n, 1 ≤ y ≤ m). The numbers written on one line are separated by spaces. It is guaranteed that all k important squares have different coordinates.

Output

In the first line print the single integer — the minimum number of plants that die during the road construction. Then print n lines each containing m characters — the garden's plan. In this plan use character "X" (uppercase Latin letter X) to represent a concrete-covered square and use character "." (dot) for a square that isn't covered with concrete. If there are multiple solutions, print any of them.

Examples

Input

3 3 2
1 2 3
1 2 3
1 2 3
1 2
3 3


Output

9
.X.
.X.
.XX


Input

4 5 4
1 4 5 1 2
2 2 2 2 7
2 4 1 4 5
3 2 1 7 1
1 1
1 5
4 1
4 4


Output

26
X..XX
XXXX.
X.X..
X.XX.
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000 * 200;
int n;
int m;
int k;
int a[200];
int c[200];
int d[200][200];
int p[200][200];
int dp[128][200];
char ans[200][200];
void drawPath(int u, int v) {
  for (; v != u; v = p[u][v]) {
    ans[v / m][v % m] = 'X';
  }
}
void drawPicture(int mask, int v) {
  int minRem = INF;
  int u;
  for (int i = 0; i < n * m; i++) {
    if (dp[mask][v] == dp[mask][i] + d[i][v] && dp[mask][i] < minRem) {
      minRem = dp[mask][i];
      u = i;
    }
  }
  drawPath(u, v);
  if (c[u] >= 0 && (1 << c[u]) == mask) {
    ans[u / m][u % m] = 'X';
    return;
  }
  for (int submask = (mask - 1) & mask; submask;
       submask = (submask - 1) & mask) {
    if (dp[mask][u] == dp[submask][u] + dp[mask ^ submask][u] - a[u]) {
      drawPicture(submask, u);
      drawPicture(mask ^ submask, u);
      return;
    }
  }
}
int main() {
  cin >> n >> m >> k;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> a[i * m + j];
      ans[i][j] = '.';
    }
  }
  memset(p, -1, sizeof(p));
  for (int i = 0; i < n * m; i++) {
    for (int j = 0; j < n * m; j++) {
      if (i == j) {
        d[i][j] = 0;
        continue;
      }
      if (abs(i / m - j / m) + abs(i % m - j % m) == 1) {
        d[i][j] = a[j];
        p[i][j] = i;
        continue;
      }
      d[i][j] = INF;
    }
  }
  for (int l = 0; l < n * m; l++) {
    for (int i = 0; i < n * m; i++) {
      for (int j = 0; j < n * m; j++) {
        if (d[i][j] > d[i][l] + d[l][j]) {
          d[i][j] = d[i][l] + d[l][j];
          p[i][j] = p[l][j];
        }
      }
    }
  }
  int x;
  int y;
  memset(c, -1, sizeof(c));
  for (int i = 0; i < k; i++) {
    cin >> x >> y;
    c[--x * m + --y] = i;
  }
  for (int mask = 1; mask < (1 << k); mask++) {
    for (int i = 0; i < n * m; i++) {
      if (c[i] >= 0 && (1 << c[i]) == mask)
        dp[mask][i] = a[i];
      else
        dp[mask][i] = INF;
      for (int submask = (mask - 1) & mask; submask;
           submask = (submask - 1) & mask) {
        dp[mask][i] =
            min(dp[mask][i], dp[submask][i] + dp[mask ^ submask][i] - a[i]);
      }
    }
    for (int i = 0; i < n * m; i++) {
      for (int j = 0; j < n * m; j++) {
        dp[mask][i] = min(dp[mask][i], dp[mask][j] + d[j][i]);
      }
    }
  }
  int minCost = INF;
  int keyPoint;
  for (int i = 0; i < n * m; i++) {
    if (minCost > dp[(1 << k) - 1][i]) {
      minCost = dp[(1 << k) - 1][i];
      keyPoint = i;
    }
  }
  drawPicture((1 << k) - 1, keyPoint);
  cout << minCost << endl;
  for (int i = 0; i < n; i++) cout << ans[i] << endl;
  return 0;
}
