#include <bits/stdc++.h>
using namespace std;
struct p {
  char d, m;
};
bool operator==(const p& a, const p& b) { return a.d == b.d && a.m == b.m; }
bool operator<(const p& a, const p& b) {
  if (a.m != b.m) return a.m < b.m;
  return a.d < b.d;
}
p d[54][54];
bool test(int i, int j) {
  set<int> s;
  for (int k = i; k < i + 3; k++)
    for (int l = j; l < j + 3; l++) s.insert(d[k][l].d);
  if (s.size() == 9) return 1;
  bool ok = 1;
  for (int k = i; k < i + 3; k++)
    for (int l = j; l < j + 3; l++)
      if (d[i][j].m != d[k][l].m) ok = 0;
  return ok;
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> d[i][j].d >> d[i][j].m;
  pair<int, int> jocker[2];
  char jr[2];
  int q = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++)
      if (d[i][j].d == 'J' && (d[i][j].m == '1' || d[i][j].m == '2')) {
        jocker[q++] = make_pair(i, j);
        jr[q - 1] = d[i][j].m;
      }
  }
  if (q == 0) {
    vector<vector<bool>> ans(n - 2, vector<bool>(m - 2));
    for (int i = 0; i < n - 2; i++) {
      for (int j = 0; j < m - 2; j++) {
        ans[i][j] = test(i, j);
      }
    }
    for (int i = 0; i < n - 2; i++) {
      for (int j = 0; j < m - 2; j++) {
        if (ans[i][j]) {
          for (int k = 0; k < n - 2; k++) {
            for (int l = 0; l < m - 2; l++) {
              if (k >= i - 2 && k <= i + 2 && l >= j - 2 && l <= j + 2)
                continue;
              if (ans[k][l]) {
                cout << "Solution exists." << endl
                     << "There are no jokers." << endl
                     << "Put the first square to (" << i + 1 << ", " << j + 1
                     << ")." << endl
                     << "Put the second square to (" << k + 1 << ", " << l + 1
                     << ").";
                return 0;
              }
            }
          }
        }
      }
    }
  }
  if (q == 1) {
    set<p> s;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        s.insert(d[i][j]);
      }
    }
    vector<p> var;
    char c = 'H', cd = '2';
    p temp;
    temp.d = cd, temp.m = c;
    for (char t = '2'; t <= '9'; t++) {
      temp.d = t;
      if (s.count(temp))
        continue;
      else
        var.push_back(temp);
    }
    temp.d = 'T';
    if (!s.count(temp)) var.push_back(temp);
    temp.d = 'A';
    if (!s.count(temp)) var.push_back(temp);
    temp.d = 'J';
    if (!s.count(temp)) var.push_back(temp);
    temp.d = 'Q';
    if (!s.count(temp)) var.push_back(temp);
    temp.d = 'K';
    if (!s.count(temp)) var.push_back(temp);
    c = 'D';
    temp.d = cd, temp.m = c;
    for (char t = '2'; t <= '9'; t++) {
      temp.d = t;
      if (s.count(temp))
        continue;
      else
        var.push_back(temp);
    }
    temp.d = 'T';
    if (!s.count(temp)) var.push_back(temp);
    temp.d = 'A';
    if (!s.count(temp)) var.push_back(temp);
    temp.d = 'J';
    if (!s.count(temp)) var.push_back(temp);
    temp.d = 'Q';
    if (!s.count(temp)) var.push_back(temp);
    temp.d = 'K';
    if (!s.count(temp)) var.push_back(temp);
    c = 'C';
    temp.d = cd, temp.m = c;
    for (char t = '2'; t <= '9'; t++) {
      temp.d = t;
      if (s.count(temp))
        continue;
      else
        var.push_back(temp);
    }
    temp.d = 'T';
    if (!s.count(temp)) var.push_back(temp);
    temp.d = 'A';
    if (!s.count(temp)) var.push_back(temp);
    temp.d = 'J';
    if (!s.count(temp)) var.push_back(temp);
    temp.d = 'Q';
    if (!s.count(temp)) var.push_back(temp);
    temp.d = 'K';
    if (!s.count(temp)) var.push_back(temp);
    c = 'S';
    temp.d = cd, temp.m = c;
    for (char t = '2'; t <= '9'; t++) {
      temp.d = t;
      if (s.count(temp))
        continue;
      else
        var.push_back(temp);
    }
    temp.d = 'T';
    if (!s.count(temp)) var.push_back(temp);
    temp.d = 'A';
    if (!s.count(temp)) var.push_back(temp);
    temp.d = 'J';
    if (!s.count(temp)) var.push_back(temp);
    temp.d = 'Q';
    if (!s.count(temp)) var.push_back(temp);
    temp.d = 'K';
    if (!s.count(temp)) var.push_back(temp);
    for (int t1 = 0; t1 < var.size(); t1++) {
      d[jocker[0].first][jocker[0].second] = var[t1];
      {
        vector<vector<bool>> ans(n - 2, vector<bool>(m - 2));
        for (int i = 0; i < n - 2; i++) {
          for (int j = 0; j < m - 2; j++) {
            ans[i][j] = test(i, j);
          }
        }
        for (int i = 0; i < n - 2; i++) {
          for (int j = 0; j < m - 2; j++) {
            if (ans[i][j]) {
              for (int k = 0; k < n - 2; k++) {
                for (int l = 0; l < m - 2; l++) {
                  if (k >= i - 2 && k <= i + 2 && l >= j - 2 && l <= j + 2)
                    continue;
                  if (ans[k][l]) {
                    cout << "Solution exists." << endl
                         << "Replace J" << jr[0] << " with " << var[t1].d
                         << var[t1].m << "." << endl
                         << "Put the first square to (" << i + 1 << ", "
                         << j + 1 << ")." << endl
                         << "Put the second square to (" << k + 1 << ", "
                         << l + 1 << ").";
                    return 0;
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  if (q == 2) {
    set<p> s;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        s.insert(d[i][j]);
      }
    }
    vector<p> var;
    char c = 'H', cd = '2';
    p temp;
    temp.d = cd, temp.m = c;
    for (char t = '2'; t <= '9'; t++) {
      temp.d = t;
      if (s.count(temp))
        continue;
      else
        var.push_back(temp);
    }
    temp.d = 'T';
    if (!s.count(temp)) var.push_back(temp);
    temp.d = 'A';
    if (!s.count(temp)) var.push_back(temp);
    temp.d = 'J';
    if (!s.count(temp)) var.push_back(temp);
    temp.d = 'Q';
    if (!s.count(temp)) var.push_back(temp);
    temp.d = 'K';
    if (!s.count(temp)) var.push_back(temp);
    c = 'D';
    temp.d = cd, temp.m = c;
    for (char t = '2'; t <= '9'; t++) {
      temp.d = t;
      if (s.count(temp))
        continue;
      else
        var.push_back(temp);
    }
    temp.d = 'T';
    if (!s.count(temp)) var.push_back(temp);
    temp.d = 'A';
    if (!s.count(temp)) var.push_back(temp);
    temp.d = 'J';
    if (!s.count(temp)) var.push_back(temp);
    temp.d = 'Q';
    if (!s.count(temp)) var.push_back(temp);
    temp.d = 'K';
    if (!s.count(temp)) var.push_back(temp);
    c = 'C';
    temp.d = cd, temp.m = c;
    for (char t = '2'; t <= '9'; t++) {
      temp.d = t;
      if (s.count(temp))
        continue;
      else
        var.push_back(temp);
    }
    temp.d = 'T';
    if (!s.count(temp)) var.push_back(temp);
    temp.d = 'A';
    if (!s.count(temp)) var.push_back(temp);
    temp.d = 'J';
    if (!s.count(temp)) var.push_back(temp);
    temp.d = 'Q';
    if (!s.count(temp)) var.push_back(temp);
    temp.d = 'K';
    if (!s.count(temp)) var.push_back(temp);
    c = 'S';
    temp.d = cd, temp.m = c;
    for (char t = '2'; t <= '9'; t++) {
      temp.d = t;
      if (s.count(temp))
        continue;
      else
        var.push_back(temp);
    }
    temp.d = 'T';
    if (!s.count(temp)) var.push_back(temp);
    temp.d = 'A';
    if (!s.count(temp)) var.push_back(temp);
    temp.d = 'J';
    if (!s.count(temp)) var.push_back(temp);
    temp.d = 'Q';
    if (!s.count(temp)) var.push_back(temp);
    temp.d = 'K';
    if (!s.count(temp)) var.push_back(temp);
    for (int t1 = 0; t1 < var.size(); t1++) {
      d[jocker[0].first][jocker[0].second] = var[t1];
      for (int t2 = 0; t2 < var.size(); t2++) {
        if (t1 == t2) continue;
        d[jocker[1].first][jocker[1].second] = var[t2];
        {
          vector<vector<bool>> ans(n - 2, vector<bool>(m - 2));
          for (int i = 0; i < n - 2; i++) {
            for (int j = 0; j < m - 2; j++) {
              ans[i][j] = test(i, j);
            }
          }
          for (int i = 0; i < n - 2; i++) {
            for (int j = 0; j < m - 2; j++) {
              if (ans[i][j]) {
                for (int k = 0; k < n - 2; k++) {
                  for (int l = 0; l < m - 2; l++) {
                    if (k >= i - 2 && k <= i + 2 && l >= j - 2 && l <= j + 2)
                      continue;
                    if (ans[k][l]) {
                      cout << "Solution exists." << endl;
                      if (jr[0] == '1') {
                        cout << "Replace J" << jr[0] << " with " << var[t1].d
                             << var[t1].m << " and J" << jr[1] << " with "
                             << var[t2].d << var[t2].m << "." << endl
                             << "Put the first square to (" << i + 1 << ", "
                             << j + 1 << ")." << endl
                             << "Put the second square to (" << k + 1 << ", "
                             << l + 1 << ").";
                      } else {
                        cout << "Replace J" << jr[1] << " with " << var[t2].d
                             << var[t2].m << " and J" << jr[0] << " with "
                             << var[t1].d << var[t1].m << "." << endl
                             << "Put the first square to (" << i + 1 << ", "
                             << j + 1 << ")." << endl
                             << "Put the second square to (" << k + 1 << ", "
                             << l + 1 << ").";
                      }
                      return 0;
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  cout << "No solution.";
  return 0;
}
