#include <bits/stdc++.h>
using namespace std;
void No() {
  puts("No solution");
  exit(0);
}
const int maxn = 400005;
const int H1 = 20160224;
const int mod1 = 998244353;
const int H2 = 23333333;
const int mod2 = 1e9 + 7;
int n, m, a, b, c, d;
char sa[2], sb[2];
int ch[256], cnt[4], p[4];
class Hashint {
 public:
  int h1, h2;
  Hashint() : h1(0), h2(0) {}
  Hashint(int _h1, int _h2) : h1(_h1), h2(_h2) {}
  Hashint operator+(const Hashint &o) const {
    return Hashint(h1 + o.h1 >= mod1 ? h1 + o.h1 - mod1 : h1 + o.h1,
                   h2 + o.h2 >= mod2 ? h2 + o.h2 - mod2 : h2 + o.h2);
  }
  Hashint operator-(const Hashint &o) const {
    return Hashint(h1 - o.h1 < 0 ? h1 - o.h1 + mod1 : h1 - o.h1,
                   h2 - o.h2 < 0 ? h2 - o.h2 + mod2 : h2 - o.h2);
  }
  Hashint operator*(const Hashint &o) const {
    return Hashint(1LL * h1 * o.h1 % mod1, 1LL * h2 * o.h2 % mod2);
  }
  bool operator<(const Hashint &o) const {
    return h1 < o.h1 || (h1 == o.h1 && h2 < o.h2);
  }
  bool operator!=(const Hashint &o) const { return h1 != o.h1 || h2 != o.h2; }
} H(H1, H2), pw[maxn];
int ansr[maxn], ansc[maxn];
inline int f(int x) {
  if (x < m)
    return 0;
  else if (x < n + m)
    return 1;
  else if (x < n + 2 * m)
    return 2;
  else
    return 3;
}
inline int g(int x) { return x - p[f(x)]; }
class Graph {
 public:
  int v;
  int ver[maxn];
  vector<int> edge[maxn];
  bool vis[maxn];
  Hashint val[maxn];
  void addedge(int u, int v) {
    edge[u].push_back(v);
    edge[v].push_back(u);
  }
  vector<pair<Hashint, int> > solve() {
    v = 2 * (n + m);
    vector<pair<Hashint, int> > res;
    for (int i = 0; i < v; i++)
      if (!vis[i]) {
        int j = i, len = 0;
        while (!vis[j]) {
          vis[j] = true;
          if (vis[edge[j][0]] && vis[edge[j][1]])
            d = (edge[j][0] == i) ? 0 : 1;
          else
            d = vis[edge[j][0]] ? 1 : 0;
          ver[len] = j << 1 | d;
          val[len++] = Hashint(f(j) + 1, f(j) + 1);
          j = edge[j][d];
        }
        Hashint cur = Hashint(0, 0);
        for (int j = 0; j < len; j++) cur = cur * H + val[j];
        pair<Hashint, int> now = make_pair(cur, ver[0]);
        for (int j = 1; j < len; j++) {
          cur = cur * H - pw[len] * val[j - 1] + val[j - 1];
          now = min(now, make_pair(cur, ver[j]));
        }
        reverse(ver, ver + len);
        reverse(val, val + len);
        cur = Hashint(0, 0);
        for (int j = 0; j < len; j++) cur = cur * H + val[j];
        now = min(now, make_pair(cur, ver[0] ^ 1));
        for (int j = 1; j < len; j++) {
          cur = cur * H - pw[len] * val[j - 1] + val[j - 1];
          now = min(now, make_pair(cur, ver[j] ^ 1));
        }
        res.push_back(now);
      }
    sort(res.begin(), res.end());
    for (int i = 0; i < v; i++) vis[i] = false;
    return res;
  }
} G1, G2;
void update(int j1, int j2) {
  if (f(j1) & 1)
    ansr[g(j2)] = g(j1);
  else
    ansc[g(j2)] = g(j1);
}
int main() {
  scanf("%d%d", &n, &m);
  ch['T'] = 0;
  ch['R'] = 1;
  ch['B'] = 2;
  ch['L'] = 3;
  p[0] = 0;
  p[1] = m;
  p[2] = n + m;
  p[3] = n + 2 * m;
  pw[0] = Hashint(1, 1);
  for (int i = 1; i <= 2 * (n + m); i++) pw[i] = pw[i - 1] * H;
  for (int i = 0; i < n + m; i++) {
    scanf("%s%s%d%d", sa, sb, &c, &d);
    a = ch[sa[0]];
    b = ch[sb[0]];
    c--;
    d--;
    G1.addedge(p[a] + c, p[b] + d);
    if (abs(a - b) != 2) {
      if (a == (b + 1) % 4) swap(a, b);
      int nc = cnt[a], nd = cnt[a];
      if (a == 0) nc = m - 1 - nc;
      if (a == 1) nc = n - 1 - nc;
      if (b == 2) nd = m - 1 - nd;
      if (b == 3) nd = n - 1 - nd;
      G2.addedge(p[a] + nc, p[b] + nd);
      cnt[a]++;
    }
  }
  if (cnt[3] + cnt[0] != cnt[1] + cnt[2] || cnt[0] + cnt[1] != cnt[2] + cnt[3])
    No();
  if (cnt[3] + cnt[0] < m && cnt[0] + cnt[1] < n) No();
  if (cnt[3] + cnt[0] < m) {
    for (int i = 0; i < m - cnt[0] - cnt[3]; i++)
      G2.addedge(p[0] + cnt[3] + i, p[2] + cnt[2] + i);
  }
  if (cnt[0] + cnt[1] < n) {
    for (int i = 0; i < n - cnt[0] - cnt[1]; i++)
      G2.addedge(p[1] + cnt[0] + i, p[3] + cnt[3] + i);
  }
  for (int i = 0; i < m; i++)
    G1.addedge(p[0] + i, p[2] + i), G2.addedge(p[0] + i, p[2] + i);
  for (int i = 0; i < n; i++)
    G1.addedge(p[1] + i, p[3] + i), G2.addedge(p[1] + i, p[3] + i);
  vector<pair<Hashint, int> > ans1 = G1.solve();
  vector<pair<Hashint, int> > ans2 = G2.solve();
  if (int(ans1.size()) != int(ans2.size())) No();
  for (int i = 0; i < n; i++) ansr[i] = i;
  for (int i = 0; i < m; i++) ansc[i] = i;
  for (int i = 0; i < int(ans1.size()); i++) {
    if (ans1[i].first != ans2[i].first) No();
    int j1 = ans1[i].second >> 1, d1 = ans1[i].second & 1;
    int j2 = ans2[i].second >> 1, d2 = ans2[i].second & 1;
    G1.vis[j1] = G2.vis[j2] = true;
    update(j1, j2);
    j1 = G1.edge[j1][d1];
    j2 = G2.edge[j2][d2];
    while (!G1.vis[j1] || !G2.vis[j2]) {
      update(j1, j2);
      G1.vis[j1] = G2.vis[j2] = true;
      j1 = G1.vis[G1.edge[j1][0]] ? G1.edge[j1][1] : G1.edge[j1][0];
      j2 = G2.vis[G2.edge[j2][0]] ? G2.edge[j2][1] : G2.edge[j2][0];
    }
  }
  for (int i = 0; i < n; i++)
    printf("%d%c", ansr[i] + 1, i == n - 1 ? '\n' : ' ');
  for (int i = 0; i < m; i++)
    printf("%d%c", ansc[i] + 1, i == m - 1 ? '\n' : ' ');
  return 0;
}
