#include <bits/stdc++.h>
using namespace std;
set<int> hs[2];
set<int>::iterator it;
struct pp {
  int ip, id, a, b;
};
pp ls[410000];
int cnt_ls;
int n, m, cnt_list[6], po[4][110000], bs[4][110000];
char ss[] = {'L', 'T', 'B', 'R'};
int pos[1256], ps[4][4], cnt, per[2][110000], root, rf;
char ch1, ch2;
bool vis[2][110000], fir, rev;
char chg(char ch) {
  if (ch == 'L') return 'T';
  if (ch == 'T') return 'L';
  if (ch == 'B') return 'R';
  if (ch == 'R') return 'B';
}
bool dfs(int ip, int id, int pre, int pre_id, int &low, int &high) {
  int i, j, s, p, q, ie, ip1, ip2, iq, npre, nlow, nhigh;
  if (fir && ip == rf && id == root) return low <= high;
  fir = true;
  vis[ip][id] = true;
  ls[cnt_ls].ip = ip;
  ls[cnt_ls++].id = id;
  if (ip == 0) {
    ip1 = 0;
    ip2 = bs[0][id];
    if (ip2 == 1 && pre != 0) {
      high = min(high, cnt_list[0] - 1);
      npre = 0;
      ls[cnt_ls - 1].a = 1;
      ls[cnt_ls - 1].b = 0;
      return dfs(1, po[0][id], npre, id, low, high);
    } else if (ip2 == 2 && pre != 1) {
      nlow = n - 1 - high;
      nhigh = n - 1 - low;
      nhigh = min(nhigh, cnt_list[1] - 1);
      low = nlow;
      high = nhigh;
      npre = 1;
      ls[cnt_ls - 1].a = -1;
      ls[cnt_ls - 1].b = n - 1;
      return dfs(1, po[0][id], npre, id, low, high);
    } else if (ip2 == 3)
      return false;
    ip1 = 3;
    ip2 = bs[3][id];
    if (ip2 == 0) return false;
    if (ip2 == 1) {
      nlow = m - 1 - high;
      nhigh = m - 1 - low;
      nlow = max(nlow, m - cnt_list[4]);
      low = nlow;
      high = nhigh;
      npre = 4;
      ls[cnt_ls - 1].a = -1;
      ls[cnt_ls - 1].b = m - 1;
      return dfs(1, po[3][id], npre, id, low, high);
    } else if (ip2 == 2) {
      nlow = low + m - n;
      nhigh = m - n + high;
      nlow = max(nlow, m - cnt_list[5]);
      low = nlow;
      high = nhigh;
      npre = 5;
      ls[cnt_ls - 1].a = 1;
      ls[cnt_ls - 1].b = m - n;
      return dfs(1, po[3][id], npre, id, low, high);
    }
  } else {
    ip1 = 1;
    ip2 = bs[1][id];
    if (ip2 == 0 && pre != 0) {
      high = min(high, cnt_list[0] - 1);
      npre = 0;
      ls[cnt_ls - 1].a = 1;
      ls[cnt_ls - 1].b = 0;
      return dfs(0, po[1][id], npre, id, low, high);
    } else if (ip2 == 2 && (pre != 3 || po[1][id] != pre_id)) {
      nlow = low - cnt_list[0] + cnt_list[1];
      nhigh = high - cnt_list[0] + cnt_list[1];
      nlow = max(nlow, cnt_list[1]);
      nhigh = min(nhigh, m - 1 - cnt_list[5]);
      low = nlow;
      high = nhigh;
      npre = 3;
      ls[cnt_ls - 1].a = 1;
      ls[cnt_ls - 1].b = cnt_list[1] - cnt_list[0];
      return dfs(1, po[1][id], npre, id, low, high);
    } else if (ip2 == 3 && pre != 4) {
      nlow = m - 1 - high;
      nhigh = m - 1 - low;
      nhigh = min(nhigh, cnt_list[4] - 1);
      low = nlow;
      high = nhigh;
      npre = 4;
      ls[cnt_ls - 1].a = -1;
      ls[cnt_ls - 1].b = m - 1;
      return dfs(0, po[1][id], npre, id, low, high);
    }
    ip1 = 2;
    ip2 = bs[2][id];
    if (ip2 == 0) {
      nlow = n - 1 - high;
      nhigh = n - 1 - low;
      nlow = max(nlow, n - cnt_list[1]);
      low = nlow;
      high = nhigh;
      npre = 1;
      ls[cnt_ls - 1].a = -1;
      ls[cnt_ls - 1].b = n - 1;
      return dfs(0, po[2][id], npre, id, low, high);
    } else if (ip2 == 1) {
      nlow = low - cnt_list[1] + cnt_list[0];
      nhigh = high - cnt_list[1] + cnt_list[0];
      nlow = max(nlow, cnt_list[0]);
      nhigh = min(nhigh, m - 1 - cnt_list[4]);
      low = nlow;
      high = nhigh;
      npre = 3;
      ls[cnt_ls - 1].a = 1;
      ls[cnt_ls - 1].b = cnt_list[0] - cnt_list[1];
      return dfs(1, po[2][id], npre, id, low, high);
    } else if (ip2 == 3) {
      nlow = low + n - m;
      nhigh = high + n - m;
      nlow = max(nlow, n - cnt_list[5]);
      low = nlow;
      high = nhigh;
      npre = 5;
      ls[cnt_ls - 1].a = 1;
      ls[cnt_ls - 1].b = n - m;
      return dfs(0, po[2][id], npre, id, low, high);
    }
  }
}
int main() {
  int i, j, s, p, q, id1, id2, ip1, ip2, id, ip, u1, u2, low, high;
  scanf("%d%d", &n, &m);
  rev = false;
  if (n > m) {
    swap(n, m);
    rev = true;
  }
  for (i = 0; i < 4; i++) pos[ss[i]] = i;
  cnt = 0;
  for (i = 0; i < 4; i++)
    for (j = i + 1; j < 4; j++) ps[i][j] = cnt++;
  memset(cnt_list, 0, sizeof(cnt_list));
  for (i = 0; i < n + m; i++) {
    ch1 = getchar();
    while (!(ch1 >= 'A' && ch1 <= 'Z')) ch1 = getchar();
    ch2 = getchar();
    while (!(ch2 >= 'A' && ch2 <= 'Z')) ch2 = getchar();
    scanf("%d%d", &id1, &id2);
    id1--;
    id2--;
    if (rev) {
      ch1 = chg(ch1);
      ch2 = chg(ch2);
    }
    if (pos[ch1] > pos[ch2]) {
      swap(ch1, ch2);
      swap(id1, id2);
    }
    id = ps[pos[ch1]][pos[ch2]];
    po[pos[ch1]][id1] = id2;
    bs[pos[ch1]][id1] = pos[ch2];
    po[pos[ch2]][id2] = id1;
    bs[pos[ch2]][id2] = pos[ch1];
    cnt_list[id]++;
  }
  if (cnt_list[0] != cnt_list[5] || cnt_list[1] != cnt_list[4]) {
    puts("No solution");
    return 0;
  }
  memset(vis, false, sizeof(vis));
  hs[0].clear();
  hs[1].clear();
  for (i = 0; i < n; i++) hs[0].insert(i);
  for (i = 0; i < m; i++) hs[1].insert(i);
  for (i = 0; i < n; i++) {
    if (vis[0][i]) continue;
    root = i;
    rf = 0;
    cnt_ls = 0;
    fir = false;
    low = 0;
    high = n - 1;
    if (!dfs(0, i, -1, -1, low, high)) {
      puts("No solution");
      return 0;
    }
    it = hs[0].lower_bound(low);
    if (it == hs[0].end() || *it > high) {
      puts("No solution");
      return 0;
    }
    low = *it;
    for (j = 0; j < cnt_ls; j++) {
      per[ls[j].ip][low] = ls[j].id + 1;
      it = hs[ls[j].ip].find(low);
      if (it == hs[ls[j].ip].end()) {
        puts("No solution");
        return 0;
      }
      hs[ls[j].ip].erase(low);
      low = ls[j].a * low + ls[j].b;
    }
  }
  for (i = 0; i < m; i++) {
    low = 0;
    high = m - 1;
    if (vis[1][i]) continue;
    rf = 1;
    root = i;
    cnt_ls = 0;
    fir = false;
    if (!dfs(1, i, -1, -1, low, high)) {
      puts("No solution");
      return 0;
    }
    it = hs[1].lower_bound(low);
    if (it == hs[1].end() || *it > high) {
      puts("No solution");
      return 0;
    }
    low = *it;
    for (j = 0; j < cnt_ls; j++) {
      per[ls[j].ip][low] = ls[j].id + 1;
      it = hs[ls[j].ip].find(low);
      if (it == hs[ls[j].ip].end()) {
        puts("No solution");
        return 0;
      }
      hs[ls[j].ip].erase(low);
      low = ls[j].a * low + ls[j].b;
    }
  }
  if (rev) {
    swap(n, m);
    for (i = 0; i < n || i < m; i++) swap(per[0][i], per[1][i]);
  }
  for (i = 0; i < n; i++) printf("%d ", per[0][i]);
  printf("\n");
  for (i = 0; i < m; i++) printf("%d ", per[1][i]);
  printf("\n");
  return 0;
}
