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;
const int maxside = 4;
const char sides[maxside + 1] = "TRBL";
const int maxn = (int)1e5;
int h, w;
inline int getnum(char ch, int pos) {
  --pos;
  int chi;
  for (chi = 0; chi < maxside && sides[chi] != ch; chi++)
    ;
  assert(chi < maxside);
  if (chi == 2) pos = w - 1 - pos;
  if (chi == 3) pos = h - 1 - pos;
  if (chi & 1) chi--, pos += w;
  if (chi == 2) chi -= 2, pos += w + h;
  assert(!chi);
  return pos;
}
inline int getSide(int pos) {
  return pos < w ? 0 : pos < w + h ? 1 : pos < 2 * w + h ? 2 : 3;
}
inline int opposite(int pos) {
  int side = getSide(pos);
  if (!(side & 1)) return 2 * w + h - 1 - pos;
  return 3 * w + 2 * h - 1 - pos;
}
struct Converter;
struct circle {
  Converter *base;
  int pos, len;
  circle() {}
  circle(Converter *_base) : base(_base) {}
  circle(Converter *_base, int _pos, int _len = 0)
      : base(_base), pos(_pos), len(_len) {}
  int build(int *res) const;
  circle getMin();
};
struct Converter {
  int go[4 * maxn];
  int w, h;
  void build(int _w, int _h);
  void adde(int s, int t);
  bool buildRight(const Converter &r);
  static int tmp[2][4 * maxn], temp[8 * maxn], used[4 * maxn];
  static int maxu;
  circle cs[2 * maxn];
  int csCnt;
  void buildCircles();
};
int Converter::tmp[2][4 * maxn], Converter::used[4 * maxn],
    Converter::temp[8 * maxn], Converter::maxu;
int circle::build(int *res) const {
  ++base->maxu;
  int rlen = 0;
  for (int cur = pos; base->used[cur] != base->maxu;) {
    base->used[cur] = base->maxu;
    res[rlen++] = cur;
    cur = base->go[cur];
    res[rlen++] = cur;
    assert(base->used[cur] != base->maxu);
    base->used[cur] = base->maxu;
    cur = opposite(cur);
  }
  return rlen;
}
inline bool operator<(const circle &c1, const circle &c2) {
  if (c1.len != c2.len) return c1.len < c2.len;
  c1.build(Converter::tmp[0]);
  c2.build(Converter::tmp[1]);
  for (int i = 0; i < c1.len; i++) {
    int s1 = getSide(Converter::tmp[0][i]), s2 = getSide(Converter::tmp[1][i]);
    if (s1 != s2) return s1 < s2;
  }
  return 0;
}
inline bool operator==(const circle &c1, const circle &c2) {
  if (c1.len != c2.len) return 0;
  c1.build(Converter::tmp[0]);
  c2.build(Converter::tmp[1]);
  for (int i = 0; i < c1.len; i++) {
    int s1 = getSide(Converter::tmp[0][i]), s2 = getSide(Converter::tmp[1][i]);
    if (s1 != s2) return 0;
  }
  return 1;
}
inline int getMinShift(int *s, int n) {
  s[n] = 0;
  int ans = 0, i, j, jpr;
  for (i = 0; i < n / 2;) {
    for (j = i + 1, jpr = i; j < n && s[jpr] <= s[j]; j++) {
      if (s[jpr] < s[j])
        jpr = i;
      else
        jpr++;
    }
    ans = i;
    for (; i <= jpr; i += j - jpr)
      ;
  }
  return ans;
}
circle circle::getMin() {
  len = build(Converter::tmp[0]);
  assert(!(len & 1));
  circle ccs[2];
  for (int it = 0; it < 2; it++) {
    for (int i = 0; i < len; i += 2)
      Converter::temp[i / 2] = Converter::temp[(i + len) / 2] =
          getSide(Converter::tmp[0][i]) * 4 + getSide(Converter::tmp[0][i + 1]);
    ccs[it] = circle(
        base, Converter::tmp[0][getMinShift(Converter::temp, len) * 2], len);
    reverse(Converter::tmp[0], Converter::tmp[0] + len);
  }
  return min(ccs[0], ccs[1]);
}
void Converter::build(int _w, int _h) { w = _w, h = _h; }
void Converter::adde(int s, int t) {
  if (s > t) swap(s, t);
  assert(s >= 0 && t < 2 * (w + h));
  go[s] = t, go[t] = s;
}
bool Converter::buildRight(const Converter &r) {
  w = r.w, h = r.h;
  int cnt[maxside][maxside];
  memset(cnt, 0, sizeof(cnt));
  for (int i = 0; i < 2 * (w + h); i++) {
    int s1 = getSide(i), s2 = getSide(r.go[i]);
    cnt[s1][s2]++;
  }
  for (int i = 0; i < maxside; i++) assert(!cnt[i][i]);
  if (cnt[0][2] && cnt[1][3]) return 0;
  memset(go, -1, sizeof(go[0]) * (2 * (w + h)));
  for (int it = 0, shift = 0; it < 4; it++) {
    if (it & 1)
      shift += h;
    else
      shift += w;
    for (int i = 0; i < cnt[it][(it + 1) & 3]; i++)
      adde(shift - 1 - i, (it < 3 ? shift : 0) + i);
  }
  for (int i = 0; i < cnt[0][2]; i++)
    adde(i + cnt[3][0], w + h + cnt[3][0] + cnt[0][2] - i - 1);
  for (int i = 0; i < cnt[1][3]; i++)
    adde(w + i + cnt[0][1], w + w + h + cnt[0][1] + cnt[1][3] - i - 1);
  for (int i = 0; i < 2 * (w + h); i++) assert(go[i] != -1 && i == go[go[i]]);
  return 1;
}
void Converter::buildCircles() {
  memset(used, 0, sizeof(used[0]) * (2 * (w + h)));
  maxu = 0;
  csCnt = 0;
  for (int i = 0; i < 2 * (w + h); i++) {
    if (used[i]) continue;
    cs[csCnt++] = circle(this, i).getMin();
  }
  sort(cs, cs + csCnt);
}
Converter cs[2];
int perm[2][maxn];
int main() {
  while (scanf("%d%d", &h, &w) >= 1) {
    cs[0].build(w, h);
    for (int i = 0; i < h + w; i++) {
      char a, b;
      int p, q;
      scanf(" %c %c%d%d", &a, &b, &p, &q);
      int n1 = getnum(a, p), n2 = getnum(b, q);
      cs[0].go[n1] = n2, cs[0].go[n2] = n1;
    }
    bool fail = 0;
    if (!cs[1].buildRight(cs[0])) {
      fail = 1;
    } else {
      cs[0].buildCircles();
      cs[1].buildCircles();
      if (cs[0].csCnt != cs[1].csCnt)
        fail = 1;
      else {
        for (int i = 0; i < cs[0].csCnt; i++) {
          if (!(cs[0].cs[i] == cs[1].cs[i])) {
            fail = 1;
            break;
          }
        }
      }
    }
    if (fail) {
      printf("No solution\n");
      continue;
    }
    memset(perm[0], -1, sizeof(perm[0][0]) * h);
    memset(perm[1], -1, sizeof(perm[1][0]) * w);
    for (int i = 0; i < cs[0].csCnt; i++) {
      int len = cs[0].cs[i].len;
      assert(len == cs[0].cs[i].build(Converter::tmp[0]));
      assert(len == cs[1].cs[i].build(Converter::tmp[1]));
      for (int i = 0; i < len; i++) {
        int pos[2] = {Converter::tmp[0][i], Converter::tmp[1][i]};
        assert(getSide(pos[0]) == getSide(pos[1]));
        int side = getSide(pos[0]);
        if (side >= 2)
          pos[0] = opposite(pos[0]), pos[1] = opposite(pos[1]), side -= 2;
        if (side == 1) {
          pos[0] -= w, pos[1] -= w;
          assert(perm[0][pos[1]] == -1 || perm[0][pos[1]] == pos[0]);
          perm[0][pos[1]] = pos[0];
        } else {
          assert(perm[1][pos[1]] == -1 || perm[1][pos[1]] == pos[0]);
          perm[1][pos[1]] = pos[0];
        }
      }
    }
    int ns[2] = {h, w};
    for (int it = 0; it < 2; it++) {
      for (int i = 0; i < ns[it]; i++)
        printf("%d%c", perm[it][i] + 1, " \n"[i == ns[it] - 1]);
    }
  }
  return 0;
}