/* Example invocation:
 * ./printer > a.ppm
 *
 * with input (via stdin)
 *
 * 3 3
 * 1 2 3
 * 2 3 1
 * 3 2 1
 */
#include <bits/stdc++.h>
using namespace std;

constexpr int squaresize = 151, linesize = 10;

struct color {
    int r, g, b;
} white = {255, 255, 255}, black = {0, 0, 0};

color from_hsl(int h, double s, double l) {
    double c = (1 - abs(2 * l - 1)) * s;
    double x = c * (1 - abs((h / 60) % 2 - 1));
    double m = l - c / 2;

    double r = 0, g = 0, b = 0;
    cerr << h << endl;

    if (h < 60)
        tie(r, g) = make_pair(c, x);
    else if (h < 120)
        tie(r, g) = make_pair(x, c);
    else if (h < 180)
        tie(g, b) = make_pair(c, x);
    else if (h < 240)
        tie(g, b) = make_pair(x, c);
    else if (h < 300)
        tie(r, b) = make_pair(x, c);
    else
        tie(r, b) = make_pair(c, x);

    r = (r + m) * 255;
    g = (g + m) * 255;
    b = (b + m) * 255;

    return color{(int)r, (int)g, (int)b};
}

color from_h(int h) { return from_hsl(h, 0.95, 0.75); }

vector<color> colors;

vector<vector<color>> ret;

int cross(double a, double b, double c, double d, double e, double f) {
    c -= a, d -= b, e -= a, f -= b;
    return c * f - e * d;
}

bool inside(int i, int j, vector<pair<double, double>> points) {
    for (int x = 0, y = 1; x < points.size(); ++x, ++y, y %= points.size())
        if (cross(i, j, points[x].first, points[x].second, points[y].first,
                  points[y].second) < 0)
            return false;
    return true;
}

void print_color(int i, int j, int x) {
    i *= (linesize + squaresize);
    j *= (linesize + squaresize);
    i += linesize;
    j += linesize;

    for (int di = 0; di < squaresize; ++di)
        for (int dj = 0; dj < squaresize; ++dj) ret[i + di][j + dj] = white;

    i += squaresize / 2;
    j += squaresize / 2;

    vector<pair<double, double>> points;

    for (int i = 0; i < x + 3; ++i) {
        double angle = x % 2 == 0 ? 2 * M_PI / (x + 3) * (2 * i + 1) / 2
                                  : 2 * M_PI / (x + 3) * (2 * i) / 2;
        double len = squaresize / 2 * 0.85;
        points.emplace_back(cos(angle) * len, sin(angle) * len);
    }

    for (int di = -squaresize / 2; di <= squaresize / 2; ++di)
        for (int dj = -squaresize / 2; dj <= squaresize / 2; ++dj)
            if (inside(di, dj, points)) ret[i + di][j + dj] = colors[x];
}

int main() {
    int n, m, k;
    cin >> n >> m >> k;

    colors.resize(max(k, 5));

    random_device rd;
    int s = 182;

    for (int i = 0; i < k; ++i) {
        cerr << s << endl;
        colors[i] = from_h(s);
        s += 180.0 / k;
        s %= 180;
    }

    colors[3] = {13, 50, 77};
    colors[1] = {238, 207, 109};
    colors[2] = {230, 57, 70};
    colors[0] = {94, 177, 191};
    colors[4] = {127, 5, 95};

    ret.resize(n * (squaresize + linesize) + linesize,
               vector<color>(m * (squaresize + linesize) + linesize, black));

    for (int i = 0; i < n; ++i)
        for (int j = 0; j < m; ++j) {
            int x;
            cin >> x;
            print_color(i, j, x - 1);
        }

    cout << "P3" << '\n';
    cout << ret[0].size() << ' ' << ret.size() << '\n';
    cout << 255 << '\n';
    for (int i = 0; i < ret.size(); ++i) {
        for (int j = 0; j < ret[i].size(); ++j) {
            cout << ret[i][j].r << ' ' << ret[i][j].g << ' ' << ret[i][j].b
                 << ' ';
        }
        cout << '\n';
    }

    return 0;
}
