#include <bits/stdc++.h>
using namespace std;
string nums = "23456789TJQKA";
string suits = "CDHS";
int n, m;
int ok(vector<vector<string> > &arr, int i, int j) {
  set<int> ss;
  set<int> sn;
  int num = 0;
  for (int k = 0; k < 3; k++) {
    for (int l = 0; l < 3; l++) {
      int x = i + k, y = j + l;
      sn.insert(nums.find(arr[x][y][0]));
      ss.insert(suits.find(arr[x][y][1]));
    }
  }
  if (ss.size() == 1 || sn.size() == 9) return true;
  return false;
}
bool overlapping(pair<int, int> f, pair<int, int> s) {
  if (abs(f.first - s.first) >= 3 || abs(f.second - s.second) >= 3) return 0;
  return 1;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  set<string> cards;
  for (int i = 0; i < nums.size(); i++) {
    for (int j = 0; j < suits.size(); j++) {
      cards.insert(string("") + nums[i] + suits[j]);
    }
  }
  cin >> n >> m;
  vector<vector<string> > arr(n, vector<string>(m));
  vector<pair<int, int> > jokers;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> arr[i][j];
      if (arr[i][j] != "J1" && arr[i][j] != "J2")
        cards.erase(arr[i][j]);
      else
        jokers.push_back({i, j});
    }
  }
  if (jokers.size() == 2) {
    if (arr[jokers[0].first][jokers[0].second] == "J2")
      swap(jokers[0], jokers[1]);
    for (string c1 : cards) {
      for (string c2 : cards) {
        if (c1 == c2) continue;
        arr[jokers[0].first][jokers[0].second] = c1;
        arr[jokers[1].first][jokers[1].second] = c2;
        vector<pair<int, int> > start;
        for (int i = 0; i + 2 < n; i++) {
          for (int j = 0; j + 2 < m; j++) {
            if (ok(arr, i, j)) {
              start.push_back({i, j});
            }
          }
        }
        for (int i = 0; i < start.size(); i++) {
          for (int j = i + 1; j < start.size(); j++) {
            if (!overlapping(start[i], start[j])) {
              cout << "Solution exists.\n";
              cout << "Replace J1 with " << c1;
              cout << " and J2 with " << c2 << ".\n";
              cout << "Put the first square to (" << start[i].first + 1 << ", "
                   << start[i].second + 1 << ").\n";
              cout << "Put the second square to (" << start[j].first + 1 << ", "
                   << start[j].second + 1 << ").\n";
              return 0;
            }
          }
        }
      }
    }
  } else if (jokers.size() == 1) {
    string jname = arr[jokers[0].first][jokers[0].second];
    for (string c1 : cards) {
      arr[jokers[0].first][jokers[0].second] = c1;
      vector<pair<int, int> > start;
      for (int i = 0; i + 2 < n; i++) {
        for (int j = 0; j + 2 < m; j++) {
          if (ok(arr, i, j)) {
            start.push_back({i, j});
          }
        }
      }
      for (int i = 0; i < start.size(); i++) {
        for (int j = i + 1; j < start.size(); j++) {
          if (!overlapping(start[i], start[j])) {
            cout << "Solution exists.\n";
            cout << "Replace " + jname + " with " << c1 << ".\n";
            cout << "Put the first square to (" << start[i].first + 1 << ", "
                 << start[i].second + 1 << ").\n";
            cout << "Put the second square to (" << start[j].first + 1 << ", "
                 << start[j].second + 1 << ").\n";
            return 0;
          }
        }
      }
    }
  } else {
    vector<pair<int, int> > start;
    for (int i = 0; i + 2 < n; i++) {
      for (int j = 0; j + 2 < m; j++) {
        if (ok(arr, i, j)) {
          start.push_back({i, j});
        }
      }
    }
    for (int i = 0; i < start.size(); i++) {
      for (int j = i + 1; j < start.size(); j++) {
        if (!overlapping(start[i], start[j])) {
          cout << "Solution exists.\n";
          cout << "There are no jokers.\n";
          cout << "Put the first square to (" << start[i].first + 1 << ", "
               << start[i].second + 1 << ").\n";
          cout << "Put the second square to (" << start[j].first + 1 << ", "
               << start[j].second + 1 << ").\n";
          return 0;
        }
      }
    }
  }
  cout << "No solution.\n";
  return 0;
}
