#include <utility> // pair make_pair
using std::pair;
using std::make_pair;
#include <tuple> // tuple(c++11) make_tuple(c++11)
using std::tuple; // get<address>(variable)
using std::make_tuple;
#include <string> // string stoi(c++11) stoll(c++11) to_string(c++11)
using std::string;
using std::stoi;
using std::stoll;
using std::to_string;
#include <queue> // queue priority_queue
using std::queue;
using std::priority_queue;
#include <stack> // stack
using std::stack;
#include <vector> // vector
using std::vector;
#include <map> // map
using std::map;
#include <set> // set
using std::set; // insert erase find count
#include <algorithm> // min max
using std::sort;
using std::lower_bound; // iterator,  >=
using std::upper_bound; // iterator,  >
using std::min;
using std::max;
using std::min_element; // iterator
using std::max_element; // iterator
#include <complex> // complex
using std::complex; // real imag
#include <iostream> // cin cout
using std::cin;
using std::cout;
using std::endl;
#include <iomanip> // setprecision fixed(manipulator)
using std::setprecision;
using std::fixed;
#include <cmath>
#include <cstdio>

#define lli long long int
#define INF (int)1e09
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define EFOR(i, m, n) for (int i = m; i <= n; i++)
#define RFOR(i, m, n) for (int i = m; i > n; i--)
#define REFOR(i, m, n) for (int i = m; i >= n; i--)
#define VSORT(v) sort((v).begin(), (v).end()) // sort vector
typedef pair<int, int> PI;
typedef tuple<int, int, int> TI;
template <typename T> using Vec = vector<T>; // c++11

int dy[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
int dx[8] = {-1, 0, 1, -1, 1, -1, 0, 1};

void dump (Vec<Vec<char>>& table) {
    FOR(i, 0, 10) {
        FOR(j, 0, 10) {
            cout << table[i][j] << " ";
        }
        cout << endl;
    }
}

bool change(Vec<Vec<char>>& table, char me, char you) {
    int ans_i = 0;
    int ans_j = 0;
    int ans_cnt = 0;

    FOR(i, 1, 9) {
        FOR(j, 1, 9) {
            if (table[i][j] != '.') {
                continue;
            }
            int cnt = 0;
            FOR(k, 0, 8) {
                int now_cnt = 0;
                int mul = 1;
                while (1) {
                    int cy = i + mul * dy[k];
                    int cx = j + mul * dx[k];
                    char moji = table[cy][cx];
                    if (moji == me) {
                        cnt += now_cnt;
                        break;
                    } else if (moji != you) {
                        break;
                    } else {
                        mul++;
                        now_cnt++;
                    }
                }
            }
            if (cnt > ans_cnt || (cnt == ans_cnt && me == 'x')) {
                ans_i = i;
                ans_j = j;
                ans_cnt = cnt;
            }
        }
    }

    if (ans_cnt == 0) {
        return false;
    } else {
        table[ans_i][ans_j] = me;
        FOR(i, 0, 8) {
            int mul = 1;
            while (1) {
                int cy = ans_i + mul * dy[i];
                int cx = ans_j + mul * dx[i];
                char moji = table[cy][cx];
                if (moji == me) {
                    RFOR(j, mul, 0) {
                        cy -= dy[i];
                        cx -= dx[i];
                        table[cy][cx] = me;
                    }
                    break;
                } else if (moji == you) {
                    mul++;
                } else {
                    break;
                }
            }
        }
        return true;
    }
}

int main(void) {
    Vec<Vec<char>> table(10, Vec<char>(10, '#'));
    FOR(i, 1, 9) {
        FOR(j, 1, 9) {
            cin >> table[i][j];
        }
    }

    bool tomoe_check = true;
    bool majyo_check = true;
    while (1) {
        tomoe_check = change(table, 'o', 'x');
        if (tomoe_check == false && majyo_check == false) {
            break;
        }
        majyo_check = change(table, 'x', 'o');
        if (tomoe_check == false && majyo_check == false) {
            break;
        }
    }
    FOR(i, 1, 9) {
        FOR(j, 1, 9) {
            cout << table[i][j];
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 3096