For this Question: Given a matrix of size NxM where every element is either ‘O’ or ‘X’, replace ‘O’ with ‘X’ if completely surrounded by ‘X’. A ‘O’ (or a set of ‘O’) is considered to be surrounded by ‘X’ if there are ‘X’ at locations just below, just above, just left and just right of it.

Examples:

Input: mat[N][M] =  {{'X', 'O', 'X', 'X', 'X', 'X'},
                     {'X', 'O', 'X', 'X', 'O', 'X'},
                     {'X', 'X', 'X', 'O', 'O', 'X'},
                     {'O', 'X', 'X', 'X', 'X', 'X'},
                     {'X', 'X', 'X', 'O', 'X', 'O'},
                     {'O', 'O', 'X', 'O', 'O', 'O'},
                    };
Output: mat[N][M] =  {{'X', 'O', 'X', 'X', 'X', 'X'},
                      {'X', 'O', 'X', 'X', 'X', 'X'},
                      {'X', 'X', 'X', 'X', 'X', 'X'},
                      {'O', 'X', 'X', 'X', 'X', 'X'},
                      {'X', 'X', 'X', 'O', 'X', 'O'},
                      {'O', 'O', 'X', 'O', 'O', 'O'},
                    };

Input: mat[N][M] =  {{'X', 'X', 'X', 'X'}
                     {'X', 'O', 'X', 'X'}
                     {'X', 'O', 'O', 'X'}
                     {'X', 'O', 'X', 'X'}
                     {'X', 'X', 'O', 'O'}
                    };
Output: mat[N][M] =  {{'X', 'X', 'X', 'X'}
                     {'X', 'X', 'X', 'X'}
                     {'X', 'X', 'X', 'X'}
                     {'X', 'X', 'X', 'X'}
                     {'X', 'X', 'O', 'O'}
                    };The first line of input contains an integer T denoting the no of test cases. Then T test cases follow. The first line of each test case contains two integers N and M denoting the size of the matrix. Then in the next line, there are N*M space separated values of the matrix.

Constraints:
1<= T <=10
1<= n, m <=100For each test case print the space separated values of the new matrix.Example:
Input:
2
1 5
X O X O X 
3 3
X X X X O X X X X

Output:
X O X O X
X X X X X X X X X, I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;

#define pu push_back
#define fi first
#define se second
#define mp make_pair
#define int long long
#define pii pair<int,int>
#define mm (s+e)/2
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(int i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define sz 200000
#define qw1 freopen("input1.txt", "r", stdin); freopen("output1.txt", "w", stdout);
#define qw2 freopen("input2.txt", "r", stdin); freopen("output2.txt", "w", stdout);
#define qw3 freopen("input3.txt", "r", stdin); freopen("output3.txt", "w", stdout);
#define qw4 freopen("input4.txt", "r", stdin); freopen("output4.txt", "w", stdout);
#define qw5 freopen("input5.txt", "r", stdin); freopen("output5.txt", "w", stdout);
#define qw6 freopen("input6.txt", "r", stdin); freopen("output6.txt", "w", stdout);
#define qw freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
char mat[1005][1005];
int N,M;

void floodFillUtil( int x, int y, char prevV, char newV) 
{ 
    // Base cases 
    if (x < 0 || x >= M || y < 0 || y >= N) 
        return; 
    if (mat[x][y] != prevV) 
        return; 
  
    // Replace the color at (x, y) 
    mat[x][y] = newV; 
  
    // Recur for north, east, south and west 
    floodFillUtil( x+1, y, prevV, newV); 
    floodFillUtil( x-1, y, prevV, newV); 
    floodFillUtil( x, y+1, prevV, newV); 
    floodFillUtil( x, y-1, prevV, newV); 
} 
  
// Returns size of maximum size subsquare matrix 
// surrounded by 'X' 
int replaceSurrounded() 
{ 
   // Step 1: Replace all 'O'  with '-' 
   for (int i=0; i<M; i++) 
      for (int j=0; j<N; j++) 
          if (mat[i][j] == 'O') 
             mat[i][j] = '-'; 
  
   // Call floodFill for all '-' lying on edges 
   for (int i=0; i<M; i++)   // Left side 
      if (mat[i][0] == '-') 
        floodFillUtil( i, 0, '-', 'O'); 
   for (int i=0; i<M; i++)  //  Right side 
      if (mat[i][N-1] == '-') 
        floodFillUtil( i, N-1, '-', 'O'); 
   for (int i=0; i<N; i++)   // Top side 
      if (mat[0][i] == '-') 
        floodFillUtil( 0, i, '-', 'O'); 
   for (int i=0; i<N; i++)  // Bottom side 
      if (mat[M-1][i] == '-') 
        floodFillUtil( M-1, i, '-', 'O'); 
  
   // Step 3: Replace all '-' with 'X' 
   for (int i=0; i<M; i++) 
      for (int j=0; j<N; j++) 
         if (mat[i][j] == '-') 
             mat[i][j] = 'X'; 
  
} 
signed main()
{
	
		int t;
		cin>>t;
		while(t>0)
		{
			t--;
            
            cin>>N>>M;
            for(int i=0;i<N;i++)
            {
            	for(int j=0;j<M;j++)
            	{
            		cin>>mat[i][j];
            		
            		
            	}
            }
            replaceSurrounded(); 
            for(int i=0;i<N;i++)
            {
            	for(int j=0;j<M;j++)
            	{
            		cout<<mat[i][j]<<" ";
            	}
            }
            cout<<endl;
		}
	
}, In this Programming Language: C++, Now tell me if this Code is compilable or not?