#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
int n, m, tl = 0, tr = 0, bl = 0, br = 0, tb = 0, lr = 0, r[100010], c[100010];
vector<pair<pair<int, int>, pair<int, int> > > g[400010];
vector<pair<vector<int>, vector<pair<int, int> > > > v[2];
pair<vector<int>, vector<pair<int, int> > > vv, vvv;
bool vis[400010];
int ch(int c, int x) {
  if (c == 'T') return x;
  if (c == 'B') return x + m;
  if (c == 'L') return x + m + m;
  return x + m + m + n;
}
int getType(int c1, int c2) {
  if ((c1 == 'T' && c2 == 'B') || (c1 == 'B' && c2 == 'T')) return 0;
  if ((c1 == 'L' && c2 == 'R') || (c1 == 'R' && c2 == 'L')) return 1;
  if ((c1 == 'T' && c2 == 'L') || (c1 == 'L' && c2 == 'T')) return 2;
  if ((c1 == 'T' && c2 == 'R') || (c1 == 'R' && c2 == 'T')) return 3;
  if ((c1 == 'B' && c2 == 'L') || (c1 == 'L' && c2 == 'B')) return 4;
  return 5;
}
bool ck() { return tl != br || tr != bl; }
void addGrid() {
  int x1, x2;
  for (int i = 1; i <= m; ++i) {
    x1 = ch('T', i);
    x2 = ch('B', i);
    g[x1].push_back(make_pair(make_pair(x2, 6), make_pair(0, i)));
    g[x2].push_back(make_pair(make_pair(x1, 6), make_pair(0, i)));
  }
  for (int i = 1; i <= n; ++i) {
    x1 = ch('L', i);
    x2 = ch('R', i);
    g[x1].push_back(make_pair(make_pair(x2, 7), make_pair(1, i)));
    g[x2].push_back(make_pair(make_pair(x1, 7), make_pair(1, i)));
  }
}
void dfs(int pos, int par) {
  vis[pos] = true;
  bool have = false;
  for (int i = 0; i < g[pos].size(); ++i) {
    if (g[pos][i].first.first == par && !have) {
      have = true;
      continue;
    }
    vv.first.push_back(g[pos][i].first.second);
    vv.second.push_back(g[pos][i].second);
    if (vis[g[pos][i].first.first]) return;
    dfs(g[pos][i].first.first, pos);
    break;
  }
}
int getMin(vector<int> x) {
  int k = 0, i = 0, j = 1;
  while (k < x.size() && i < x.size() && j < x.size()) {
    if (x[(i + k) % x.size()] == x[(j + k) % x.size()])
      ++k;
    else {
      if (x[(i + k) % x.size()] > x[(j + k) % x.size()])
        i += k + 1;
      else
        j += k + 1;
      if (i == j) i++;
      k = 0;
    }
  }
  return min(i, j);
}
void calcCyc(int w) {
  for (int i = 0; i < n + n + m + m + 5; ++i) vis[i] = false;
  for (int i = 1; i <= n + n + m + m; ++i)
    if (!vis[i]) {
      vv.first.clear();
      vv.second.clear();
      dfs(i, 0);
      vvv = vv;
      int mn = getMin(vv.first);
      vector<int> tmp1;
      tmp1.clear();
      for (int j = mn; j < vv.first.size(); ++j) tmp1.push_back(vv.first[j]);
      for (int j = 0; j < mn; ++j) tmp1.push_back(vv.first[j]);
      vv.first = tmp1;
      vector<pair<int, int> > tmp2;
      tmp2.clear();
      for (int j = mn; j < vv.second.size(); ++j) tmp2.push_back(vv.second[j]);
      for (int j = 0; j < mn; ++j) tmp2.push_back(vv.second[j]);
      vv.second = tmp2;
      reverse(vvv.first.begin(), vvv.first.end());
      reverse(vvv.second.begin(), vvv.second.end());
      mn = getMin(vvv.first);
      tmp1.clear();
      for (int j = mn; j < vvv.first.size(); ++j) tmp1.push_back(vvv.first[j]);
      for (int j = 0; j < mn; ++j) tmp1.push_back(vvv.first[j]);
      vvv.first = tmp1;
      tmp2.clear();
      for (int j = mn; j < vvv.second.size(); ++j)
        tmp2.push_back(vvv.second[j]);
      for (int j = 0; j < mn; ++j) tmp2.push_back(vvv.second[j]);
      vvv.second = tmp2;
      v[w].push_back(min(vv, vvv));
    }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  char c1, c2;
  int x1, x2;
  for (int i = 0; i < n + m; ++i) {
    cin >> c1 >> c2 >> x1 >> x2;
    x1 = ch(c1, x1);
    x2 = ch(c2, x2);
    int ty = getType(c1, c2);
    if (ty == 0)
      ++tb;
    else if (ty == 1)
      ++lr;
    else if (ty == 2)
      ++tl;
    else if (ty == 3)
      ++tr;
    else if (ty == 4)
      ++bl;
    else
      ++br;
    g[x1].push_back(make_pair(make_pair(x2, ty), make_pair(0, 0)));
    g[x2].push_back(make_pair(make_pair(x1, ty), make_pair(0, 0)));
  }
  if ((tb > 0 && lr > 0) || ck()) {
    puts("No solution");
    return 0;
  }
  addGrid();
  calcCyc(0);
  sort(v[0].begin(), v[0].end());
  for (int i = 0; i < n + n + m + m + 5; ++i) g[i].clear();
  addGrid();
  for (int i = 1; i <= tl; ++i) {
    x1 = ch('T', i);
    x2 = ch('L', i);
    int ty = getType('T', 'L');
    g[x1].push_back(make_pair(make_pair(x2, ty), make_pair(0, 0)));
    g[x2].push_back(make_pair(make_pair(x1, ty), make_pair(0, 0)));
  }
  for (int i = 1; i <= bl; ++i) {
    x1 = ch('L', n - i + 1);
    x2 = ch('B', i);
    int ty = getType('B', 'L');
    g[x1].push_back(make_pair(make_pair(x2, ty), make_pair(0, 0)));
    g[x2].push_back(make_pair(make_pair(x1, ty), make_pair(0, 0)));
  }
  for (int i = 1; i <= tr; ++i) {
    x1 = ch('T', m - i + 1);
    x2 = ch('R', i);
    int ty = getType('T', 'R');
    g[x1].push_back(make_pair(make_pair(x2, ty), make_pair(0, 0)));
    g[x2].push_back(make_pair(make_pair(x1, ty), make_pair(0, 0)));
  }
  for (int i = 1; i <= br; ++i) {
    x1 = ch('B', m - i + 1);
    x2 = ch('R', n - i + 1);
    int ty = getType('B', 'R');
    g[x1].push_back(make_pair(make_pair(x2, ty), make_pair(0, 0)));
    g[x2].push_back(make_pair(make_pair(x1, ty), make_pair(0, 0)));
  }
  if (tb > 0) {
    for (int i = tl + 1, j = bl + 1; i < m - tr + 1; ++i, ++j) {
      x1 = ch('T', i);
      x2 = ch('B', j);
      int ty = getType('T', 'B');
      g[x1].push_back(make_pair(make_pair(x2, ty), make_pair(0, 0)));
      g[x2].push_back(make_pair(make_pair(x1, ty), make_pair(0, 0)));
    }
  } else {
    for (int i = tl + 1, j = tr + 1; i < n - bl + 1; ++i, ++j) {
      x1 = ch('L', i);
      x2 = ch('R', j);
      int ty = getType('L', 'R');
      g[x1].push_back(make_pair(make_pair(x2, ty), make_pair(0, 0)));
      g[x2].push_back(make_pair(make_pair(x1, ty), make_pair(0, 0)));
    }
  }
  calcCyc(1);
  sort(v[1].begin(), v[1].end());
  bool ok = true;
  if (v[0].size() != v[1].size()) ok = false;
  if (ok)
    for (int i = 0; i < v[0].size(); ++i)
      if (v[0][i].first != v[1][i].first) ok = false;
  if (!ok) {
    puts("No solution");
    return 0;
  }
  for (int i = 0; i < v[0].size(); ++i)
    for (int j = 0; j < v[0][i].first.size(); ++j)
      if (v[0][i].second[j].second > 0) {
        if (v[0][i].second[j].first == 0)
          c[v[1][i].second[j].second] = v[0][i].second[j].second;
        else
          r[v[1][i].second[j].second] = v[0][i].second[j].second;
      }
  for (int i = 1; i <= n; ++i) cout << r[i] << ' ';
  cout << endl;
  for (int i = 1; i <= m; ++i) cout << c[i] << ' ';
  cout << endl;
  return 0;
}
