Problem: Emuskald is an innovative musician and always tries to push the boundaries of music production. Now he has come up with an idea for a revolutionary musical instrument — a rectangular harp.

A rectangular harp is a rectangle n × m consisting of n rows and m columns. The rows are numbered 1 to n from top to bottom. Similarly the columns are numbered 1 to m from left to right. String pins are spaced evenly across every side, one per unit. Thus there are n pins on the left and right sides of the harp and m pins on its top and bottom. The harp has exactly n + m different strings, each string connecting two different pins, each on a different side of the harp.

Emuskald has ordered his apprentice to construct the first ever rectangular harp. However, he didn't mention that no two strings can cross, otherwise it would be impossible to play the harp. Two strings cross if the segments connecting their pins intersect. To fix the harp, Emuskald can perform operations of two types: 

  1. pick two different columns and swap their pins on each side of the harp, not changing the pins that connect each string; 
  2. pick two different rows and swap their pins on each side of the harp, not changing the pins that connect each string; 



In the following example, he can fix the harp by swapping two columns: 

<image>

Help Emuskald complete his creation and find the permutations how the rows and columns of the harp need to be rearranged, or tell that it is impossible to do so. He can detach and reattach each string to its pins, so the physical layout of the strings doesn't matter.

Input

The first line of input contains two space-separated integers numbers n and m (1 ≤ n, m ≤ 105), the height and width of the harp in units. Each of the following n + m lines contains 4 space-separated tokens, describing a single string: two symbols ai, bi and two integer numbers pi, qi. The pair ai, pi describes the first pin, and the pair bi, qi describes the second pin of the string;

A pair s, x describes the position of a single pin in a following way: 

  1. s is equal to one of the symbols "L", "T", "R" or "B" (without quotes), which means that the pin is positioned on the left, top, right or bottom side of the harp accordingly; 
  2. x is equal to the number of the row, if the pin is on the left or right border of the harp, and to the number of the column, if the pin is on the top or bottom border of the harp. 



It is guaranteed that no two different strings are connected to the same pin.

Output

If it is possible to rearrange the rows and columns to fix the harp, on the first line output n space-separated integers — the old numbers of rows now placed from top to bottom in the fixed harp. On the second line, output m space-separated integers — the old numbers of columns now placed from left to right in the fixed harp.

If it is impossible to rearrange the rows and columns to fix the harp, output "No solution" (without quotes).

Examples

Input

3 4
L T 1 3
L B 2 2
L B 3 3
T R 1 2
T B 2 1
T R 4 1
B R 4 3


Output

1 2 3 
3 2 1 4 


Input

3 3
L T 1 1
T R 3 1
R B 3 3
B L 1 3
L R 2 2
T B 2 2


Output

No solution

Solution (in CPP):

Solution:
#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;
}