#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <functional>
#include <complex>
#include <queue>
#include <stack>
#include <cmath>
#include <cassert>
#include <tuple>
using namespace std;
typedef long long LL;
typedef complex<double> CMP;

class TwoDimensionalSort { public:
	vector <int> sortLetters(vector <string> board)
	{
		vector<int> ans;
		int next_x = 0;
		for (int y = 0; y < 26; ++y) {
			int np = 26 - count(board[y].begin(), board[y].end(), '.');
			// shift to [next_x .. next_x+np)
			for (;;) {
				int done = 0;
				for (int x = 0, i = 0; x < 26; ++x) {
					if (board[y][x] != '.') {
						int xx = next_x + i;
						if (xx == x)
							done++;
						else if(board[y][xx]=='.'){
							int l = min(x, xx) + 1;
							int r = max(x, xx);
							if (count(board[y].begin() + l, board[y].begin() + r, '.') == r - l) {
								ans.push_back(y);
								ans.push_back(x);
								ans.push_back(y);
								ans.push_back(xx);
								board[y][xx] = board[y][x];
								board[y][x] = '.';
								break;
							}
						}
						++i;
					}
				}
				if (done == np)
					break;
			}
			next_x += np;
		}

		for (int y = 0; y < 26; ++y) {
			for (int x = 0; x < 26; ++x) {
				if (board[y][x] != '.') {
					int yy = board[y][x] - 'A';
					if (y != yy) {
						ans.push_back(y);
						ans.push_back(x);
						ans.push_back(yy);
						ans.push_back(x);
					}
				}
			}
		}
		cerr << ans.size() / 4 << endl;
		return ans;
	}
};

// BEGIN CUT HERE
#include <ctime>
double start_time; string timer()
 { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v)
 { os << "{ ";
   for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it)
   os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; }
void verify_case(const vector <int>& Expected, const vector <int>& Received) {
 bool ok = (Expected == Received);
 if(ok) cerr << "PASSED" << timer() << endl;  else { cerr << "FAILED" << timer() << endl;
 cerr << "\to: " << Expected << endl << "\tx: " << Received << endl; } }
#define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock();
#define END	 verify_case(_, TwoDimensionalSort().sortLetters(board));}
int main(){

CASE(0)
	string board_[] = {"..........................",
 "..........................",
 "..........................",
 "..........................",
 "..........................",
 "..........................",
 "..........................",
 "..........................",
 "..........................",
 "..........................",
 "..........................",
 "..........................",
 "..........................",
 "..........................",
 "..........................",
 "..........................",
 "..........................",
 "..........................",
 "..........................",
 "..........................",
 "..........................",
 "..........................",
 "..........................",
 "..........................",
 "..........................",
 ".........................."};
	  vector <string> board(board_, board_+sizeof(board_)/sizeof(*board_)); 
	vector <int> _; 
END
CASE(1)
	string board_[] = {"..........................",
 "..........................",
 "......B...................",
 "..............Q...........",
 "..........................",
 "..........................",
 "..........................",
 "..........................",
 "..........................",
 "..........................",
 "..........................",
 "..........................",
 "..........................",
 "..........................",
 "..........................",
 "..........................",
 "..........................",
 "..........................",
 "..........................",
 "..........................",
 "..........................",
 "..........................",
 "..........................",
 "..........................",
 "..........................",
 ".........................."};
	  vector <string> board(board_, board_+sizeof(board_)/sizeof(*board_)); 
	int __[] = {3, 14, 3, 17 };
	  vector <int> _(__, __+sizeof(__)/sizeof(*__)); 
END
CASE(2)
	string board_[] = {"..........................",
 "..........................",
 "..........................",
 ".....BCDE.................",
 ".....F....................",
 ".....G.A..................",
 ".....H....................",
 "..........................",
 "..........................",
 "..........................",
 "..........................",
 "..........................",
 "..........................",
 "..........................",
 "..........................",
 "..........................",
 "..........................",
 "..........................",
 "..........................",
 "..........................",
 "..........................",
 "..........................",
 "..........................",
 "..........................",
 "..........................",
 ".........................."};
	  vector <string> board(board_, board_+sizeof(board_)/sizeof(*board_)); 
	int __[] = {5, 7, 5, 9, 5, 9, 2, 9 };
	  vector <int> _(__, __+sizeof(__)/sizeof(*__)); 
END
CASE(3)
	string board_[] = {"..........................",
 "..........................",
 "..........................",
 ".....BCED.................",
 ".....F....................",
 ".....G.A..................",
 ".....H....................",
 "..........................",
 "..........................",
 "..........................",
 "..........................",
 "..........................",
 "..........................",
 "..........................",
 "..........................",
 "..........................",
 "..........................",
 "..........................",
 "..........................",
 "..........................",
 "..........................",
 "..........................",
 "..........................",
 "..........................",
 "..........................",
 ".........................."};
	  vector <string> board(board_, board_+sizeof(board_)/sizeof(*board_)); 
	int __[] = {3, 7, 2, 7, 2, 7, 2, 11, 5, 7, 0, 7, 2, 11, 3, 11 };
	  vector <int> _(__, __+sizeof(__)/sizeof(*__)); 
	  END
		  CASE(4)
		  string board_[] = {
				  "..........................",
				  "..........................",
				  "..........................",
				  "..........................",
				  "..............P...........",
				  "..............Q...........",
				  "..............N...........",
				  "..............X...........",
				  "..............E...........",
				  "..............H...........",
				  "..............L...........",
				  "..............O...........",
				  "..............J...........",
				  "..............B...........",
				  "..............Y...........",
				  "..............A...........",
				  "..............T...........",
				  "..............I...........",
				  "..............D...........",
				  "..............G...........",
				  "..............U...........",
				  "..............S...........",
				  "..............K...........",
				  "..............C...........",
				  "..........................",
				  ".........................." };
	  vector <string> board(board_, board_+sizeof(board_)/sizeof(*board_)); 
	  int __[] = { -1 };
	  vector <int> _(__, __+sizeof(__)/sizeof(*__)); 
END
/*
CASE(5)
	string board_[] = ;
	  vector <string> board(board_, board_+sizeof(board_)/sizeof(*board_)); 
	int __[] = ;
	  vector <int> _(__, __+sizeof(__)/sizeof(*__)); 
END
*/
}
// END CUT HERE
