#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

#include <array>

using namespace std;
vector<vector<char>>data;

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

int check ( int i , int j , char x , char y , int z )
{
	//vector<vector<char>>data2 = data;
	if( data[i][j] != '.' )return 0;
	int memo = 0;
	for( size_t k = 0; k < 8; k++ )
	{
		int t = 1;
		while( data[i + t* dx[k]][j + t*dy[k]] == y )
		{
			t++;
		}
		if( data[i + t* dx[k]][j + t*dy[k]] == x )
		{
			memo += t - 1;

			if( z )
			{
				for( size_t l = 0; l < t; l++ )
				{
					data[i + l* dx[k]][j + l*dy[k]] = x;
				}
			}
		}
	}
	return memo;
}

int func ( bool x )
{
	int memo = 0;
	pair<int , int>d;
	if( x )
	{
		for( int i = 8; i > 0; i-- )
		{
			for( int j = 8; j > 0; j-- )
			{
				int memo2 = check ( i , j , 'x' , 'o' , 0 );
				if( memo < memo2 )
				{
					d.first = i;
					d.second = j;
					memo = memo2;
				}
			}
		}
		if( memo )
		check ( d.first , d.second , 'x' , 'o' , 1 );
	} else
	{
		for( int i = 1; i < 9; i++ )
		{
			for( int j = 1; j < 9; j++ )
			{
				int memo2 = check ( i , j , 'o' , 'x' , 0 );
				if( memo < memo2 )
				{
					d.first = i;
					d.second = j;
					memo = memo2;
				}
			}
		}
		if( memo )
		check ( d.first , d.second , 'o' , 'x' , 1 );
	}
	return memo;
}

int main ()
{
	data.resize ( 10 );
	for( size_t i = 0; i < 10; i++ )
	{
		data[i].resize ( 10 );
		for( size_t j = 0; j < 10; j++ )
		{
			if( i == 0 || i == 9 || j == 0 || j == 9 )
			{
				data[i][j] = '#';
			} else
			{
				cin >> data[i][j];
			}
		}
	}
	int f = 1;
	while( f )
	{
		f = 0;
		f += func ( 0 );
		f += func ( 1 );

	}
	for( size_t i = 1; i <= 8; i++ )
	{
		for( size_t j = 1; j <= 8; j++ )
		{
			cout << data[i][j];
		}
		cout << endl;
	}
}

Measured memory_bytes: 1180