#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1);
bool rota;
int n, m, S, V, N;
int per[410000], E[410000], good_E[410000], vis[410000], a[410000 * 2],
    b[410000 * 2], pattern[410000], id[410000], fail[410000], debug[410000];
void END() {
  printf("No solution\n");
  exit(0);
}
int ch(char c, int x) {
  if (rota) {
    if (c == 'L')
      c = 'T';
    else if (c == 'B')
      c = 'R';
    else if (c == 'R')
      c = 'B';
    else
      c = 'L';
  }
  return (c == 'T' ? 0 : c == 'L' ? 2 * m : c == 'B' ? m : 2 * m + n) + x;
}
char dir(int x) {
  if (x >= 1 && x <= m) return 'T';
  if (x > 2 * m && x <= 2 * m + n) return 'L';
  if (x > m && x <= 2 * m) return 'B';
  if (x > 2 * m + n) return 'R';
}
int gettype(int x, int y) {
  if (dir(x) == 'T' && dir(y) == 'L') return 1;
  if (dir(x) == 'T' && dir(y) == 'R') return 2;
  if (dir(x) == 'L' && dir(y) == 'B') return 3;
  if (dir(x) == 'R' && dir(y) == 'B') return 4;
  if (dir(x) == 'T' && dir(y) == 'B') return 5;
  if (dir(x) == 'L' && dir(y) == 'R') END();
  return gettype(y, x);
}
int getnum(int x) {
  if (dir(x) == 'T') return x;
  if (dir(x) == 'B') return x - m;
  if (dir(x) == 'L') return x - m;
  return x - m - n;
}
void init() {
  scanf("%d%d", &n, &m);
  if (n > m) {
    swap(n, m);
    rota = 1;
  }
  for (int i = 1; i <= n + m; ++i) {
    char c1, c2;
    int x1, x2;
    scanf("\n%c %c%d%d", &c1, &c2, &x1, &x2);
    int u = ch(c1, x1), v = ch(c2, x2);
    E[u] = v;
    E[v] = u;
  }
}
void print() {
  if (S) END();
  if (rota) {
    for (int i = 1; i <= m; ++i) printf("%d ", per[i]);
    puts("");
    for (int i = 1; i <= n; ++i) printf("%d ", per[i + m] - m);
  } else {
    for (int i = 1; i <= n; ++i) printf("%d ", per[i + m] - m);
    puts("");
    for (int i = 1; i <= m; ++i) printf("%d ", per[i]);
  }
}
void link_good(int x, int y) {
  assert(good_E[x] == 0);
  assert(good_E[y] == 0);
  good_E[x] = y;
  good_E[y] = x;
}
int Search(int x, bool good, int *p1, int *p2) {
  int y = x, tot, z;
  tot = 0;
  for (;;) {
    if (good) {
      z = good_E[y];
    } else
      z = E[y];
    p1[++tot] = gettype(y, z);
    p2[tot] = getnum(y);
    if (!good) vis[z] = 1;
    y = z;
    if (dir(y) == 'T')
      y += m;
    else if (dir(y) == 'B')
      y -= m;
    else if (dir(y) == 'L')
      y += n;
    else
      y -= n;
    if (!good) vis[y] = 1;
    if (y == x) break;
  }
  return tot;
}
void prep_kmp() {
  int p;
  fail[0] = -1;
  for (int i = 1; i <= N; ++i) {
    for (p = fail[i - 1]; p != -1 && pattern[i] != pattern[p + 1]; p = fail[p])
      ;
    fail[i] = ++p;
  }
}
void solve_circle(int s) {
  if (s != 4 && s != N) END();
  if (s == 4 && a[1] == 1 && a[2] == 2 && a[3] == 4 && a[4] == 3) {
    if (!S) END();
    per[S] = b[1];
    per[S + m] = b[2];
    per[m - S + 1] = b[3];
    per[n - S + 1 + m] = b[4];
    S--;
    return;
  }
  if (s == 4 && a[1] == 2 && a[2] == 1 && a[3] == 3 && a[4] == 4) {
    if (!S) END();
    per[m - S + 1] = b[1];
    per[S + m] = b[2];
    per[S] = b[3];
    per[n - S + 1 + m] = b[4];
    S--;
    return;
  }
  if (s != N) END();
  for (int i = 1; i <= N; ++i) a[i + N] = a[i], b[i + N] = b[i];
  int p = 0;
  for (int i = 1; i <= N + N; ++i) {
    while (p != -1 && a[i] != pattern[p + 1]) p = fail[p];
    p++;
    if (p == N) {
      Search(++V, 1, id, id);
      for (int j = i - N + 1; j <= i; ++j) per[id[j - (i - N + 1) + 1]] = b[j];
      return;
    }
  }
  END();
}
void work() {
  int s[6] = {0}, D;
  for (int i = 1; i <= 2 * (m + n); ++i) s[gettype(i, E[i])]++;
  if (s[1] != s[4] || s[2] != s[3] || s[1] + s[2] != n * 2) END();
  S = min(s[1], s[2]) / 2;
  V = S;
  if (s[1] < s[2])
    D = n - 2 * S;
  else
    D = -(n - 2 * S);
  for (int i = s[1] / 2 + 1; i <= m - s[2] / 2; ++i) link_good(i, i + D + m);
  for (int i = 1; i <= s[1] / 2; ++i) {
    link_good(2 * m + i, i);
    link_good(2 * m + 1 - i, 2 * (n + m) + 1 - i);
  }
  for (int i = 1; i <= s[2] / 2; ++i) {
    link_good(2 * m + n + 1 - i, m + i);
    link_good(m + 1 - i, 2 * m + n + i);
  }
  N = Search(V + 1, 1, pattern, id);
  prep_kmp();
  for (int i = 1; i <= 2 * (n + m); ++i)
    if (!vis[i]) {
      int s = Search(i, 0, a, b);
      solve_circle(s);
    }
}
int main() {
  init();
  work();
  print();
}
