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 MaxN = 100000;
class no_solution_error : public exception {};
struct rectstr {
  int tp1, tp2;
  int p1, p2;
  inline pair<int, int> tp() { return make_pair(tp1, tp2); }
};
int n, m;
rectstr a[MaxN * 2];
int perR[MaxN + 1], perC[MaxN + 1];
int cptotp(char cp) {
  switch (cp) {
    case 'L':
      return 0;
    case 'T':
      return 1;
    case 'R':
      return 2;
    case 'B':
      return 3;
    default:
      return -1;
  }
}
int tpptov(int tp, int p) {
  switch (tp) {
    case 0:
      return p - 1;
    case 1:
      return n + p - 1;
    case 2:
      return n + m + p - 1;
    case 3:
      return n + m + n + p - 1;
    default:
      return -1;
  }
}
inline int rectstrv1(const rectstr &r) { return tpptov(r.tp1, r.p1); }
inline int rectstrv2(const rectstr &r) { return tpptov(r.tp2, r.p2); }
inline int rectstrv(const rectstr &r, int c) {
  if (c == 1)
    return rectstrv1(r);
  else
    return rectstrv2(r);
}
inline int rectstrc(const rectstr &r, int v) {
  if (rectstrv1(r) == v)
    return 1;
  else
    return 2;
}
inline int rectstrbro(const rectstr &r, int v) {
  if (rectstrv1(r) != v)
    return rectstrv1(r);
  else
    return rectstrv2(r);
}
inline int rectoppov(int v) {
  if (v < n + m)
    return v + n + m;
  else
    return v - n - m;
}
inline void solensure(bool b) {
  if (!b) throw no_solution_error();
}
void handle() {
  solensure(m >= n);
  int cntT[4][4] = {};
  for (int i = 0; i < n + m; i++) cntT[a[i].tp1][a[i].tp2]++;
  solensure(cntT[0][1] == cntT[2][3]);
  solensure(cntT[0][3] == cntT[1][2]);
  int lA = cntT[0][1];
  int lB = cntT[0][3];
  int lD = lB - lA;
  int stdcir_n = 0;
  static pair<int, int> stdcirtp[MaxN * 4];
  static int stdnext[MaxN * 4];
  if (m > min(lA, lB) * 2) {
    int tp = 1;
    int p = min(lA, lB) + 1;
    do {
      if (tp == 0) {
        if (p <= lA) {
          stdcirtp[stdcir_n++] = make_pair(0, 1);
          tp = 1;
        } else {
          stdcirtp[stdcir_n++] = make_pair(0, 3);
          p = n + 1 - p;
          tp = 3;
        }
      } else if (tp == 1) {
        if (p <= lA) {
          stdcirtp[stdcir_n++] = make_pair(0, 1);
          tp = 0;
        } else if (p <= m - lB) {
          stdcirtp[stdcir_n++] = make_pair(1, 3);
          p += lD;
          tp = 3;
        } else {
          stdcirtp[stdcir_n++] = make_pair(1, 2);
          p = m + 1 - p;
          tp = 2;
        }
      } else if (tp == 2) {
        if (p <= lB) {
          stdcirtp[stdcir_n++] = make_pair(1, 2);
          p = m + 1 - p;
          tp = 1;
        } else {
          stdcirtp[stdcir_n++] = make_pair(2, 3);
          p = p - n + m;
          tp = 3;
        }
      } else if (tp == 3) {
        if (p <= lB) {
          stdcirtp[stdcir_n++] = make_pair(0, 3);
          p = n + 1 - p;
          tp = 0;
        } else if (p <= m - lA) {
          stdcirtp[stdcir_n++] = make_pair(1, 3);
          p -= lD;
          tp = 1;
        } else {
          stdcirtp[stdcir_n++] = make_pair(2, 3);
          p = p - m + n;
          tp = 2;
        }
      }
      tp = (tp + 2) % 4;
    } while (!(tp == 1 && p == min(lA, lB) + 1));
    stdnext[0] = -1;
    for (int i = 1, j = -1; i < stdcir_n; i++) {
      while (j >= 0 && stdcirtp[i] != stdcirtp[j + 1]) j = stdnext[j];
      if (stdcirtp[i] == stdcirtp[j + 1]) j++;
      stdnext[i] = j;
    }
  }
  static int bel[MaxN * 4];
  for (int i = 0; i < n + m; i++) {
    bel[rectstrv1(a[i])] = i;
    bel[rectstrv2(a[i])] = i;
  }
  int nCorner = 0;
  int nMid = 0;
  static bool book[MaxN * 4];
  for (int st = 0; st < n + m; st++)
    if (!book[st]) {
      int cir_n = 0;
      static int cir[MaxN * 4];
      int stV;
      if (a[st].tp() == make_pair(0, 1))
        stV = rectstrv2(a[st]);
      else if (a[st].tp() == make_pair(1, 2))
        stV = rectstrv1(a[st]);
      else if (a[st].tp() == make_pair(1, 3))
        stV = rectstrv1(a[st]);
      else
        continue;
      int curV = stV;
      int curI = st;
      while (true) {
        book[curI] = true;
        cir[cir_n++] = curI;
        curV = rectoppov(rectstrbro(a[curI], curV));
        curI = bel[curV];
        if (book[curI]) {
          solensure(curV == stV);
          break;
        }
      }
      int fstC;
      if (cir_n == 4 && a[cir[0]].tp() == make_pair(1, 2) &&
          a[cir[1]].tp() == make_pair(0, 1) &&
          a[cir[2]].tp() == make_pair(0, 3) &&
          a[cir[3]].tp() == make_pair(2, 3)) {
        solensure(!perC[a[cir[0]].p1]);
        nCorner++;
        perC[a[cir[0]].p1] = m + 1 - nCorner;
        fstC = 1;
      } else if (cir_n == 4 && a[cir[0]].tp() == make_pair(0, 1) &&
                 a[cir[1]].tp() == make_pair(1, 2) &&
                 a[cir[2]].tp() == make_pair(2, 3) &&
                 a[cir[3]].tp() == make_pair(0, 3)) {
        solensure(!perC[a[cir[0]].p2]);
        nCorner++;
        perC[a[cir[0]].p2] = nCorner;
        fstC = 2;
      } else {
        solensure(cir_n == stdcir_n);
        int sj = -1;
        for (int i = 0, j = -1; i < cir_n * 2; i++) {
          while (j >= 0 && a[cir[i % cir_n]].tp() != stdcirtp[j + 1])
            j = stdnext[j];
          if (a[cir[i % cir_n]].tp() == stdcirtp[j + 1]) j++;
          if (j == stdcir_n - 1) {
            sj = i - stdcir_n + 1;
            break;
          }
        }
        solensure(sj != -1);
        rotate(cir, cir + sj, cir + cir_n);
        if (a[cir[0]].tp() == make_pair(0, 1)) {
          solensure(!perC[a[cir[0]].p2]);
          nMid++;
          perC[a[cir[0]].p2] = min(lA, lB) + nMid;
          fstC = 2;
        } else {
          solensure(!perC[a[cir[0]].p1]);
          nMid++;
          perC[a[cir[0]].p1] = min(lA, lB) + nMid;
          fstC = 1;
        }
      }
      for (int i = 0, c = fstC; i + 1 < cir_n;
           c = rectstrc(a[cir[i + 1]], rectoppov(rectstrv(a[cir[i]], 3 - c))),
               i++) {
        if (a[cir[i]].tp() == make_pair(0, 1)) {
          if (c == 1)
            perC[a[cir[i]].p2] = perR[a[cir[i]].p1];
          else
            perR[a[cir[i]].p1] = perC[a[cir[i]].p2];
        } else if (a[cir[i]].tp() == make_pair(0, 3)) {
          if (c == 1)
            perC[a[cir[i]].p2] = n + 1 - perR[a[cir[i]].p1];
          else
            perR[a[cir[i]].p1] = n + 1 - perC[a[cir[i]].p2];
        } else if (a[cir[i]].tp() == make_pair(1, 2)) {
          if (c == 1)
            perR[a[cir[i]].p2] = m + 1 - perC[a[cir[i]].p1];
          else
            perC[a[cir[i]].p1] = m + 1 - perR[a[cir[i]].p2];
        } else if (a[cir[i]].tp() == make_pair(1, 3)) {
          if (c == 1)
            perC[a[cir[i]].p2] = perC[a[cir[i]].p1] + lD;
          else
            perC[a[cir[i]].p1] = perC[a[cir[i]].p2] - lD;
        } else if (a[cir[i]].tp() == make_pair(2, 3)) {
          if (c == 1)
            perC[a[cir[i]].p2] = perR[a[cir[i]].p1] + m - n;
          else
            perR[a[cir[i]].p1] = perC[a[cir[i]].p2] - m + n;
        }
      }
    }
}
int main() {
  try {
    cin >> n >> m;
    bool hasV = false, hasH = false;
    for (int i = 0; i < n + m; i++) {
      char cp1, cp2;
      int p1, p2;
      scanf(" %c %c %d %d", &cp1, &cp2, &p1, &p2);
      a[i].tp1 = cptotp(cp1);
      a[i].tp2 = cptotp(cp2);
      a[i].p1 = p1;
      a[i].p2 = p2;
      if (a[i].tp1 > a[i].tp2) swap(a[i].tp1, a[i].tp2), swap(a[i].p1, a[i].p2);
      if (a[i].tp() == make_pair(0, 2)) hasH = true;
      if (a[i].tp() == make_pair(1, 3)) hasV = true;
    }
    if (hasH && hasV) throw no_solution_error();
    if (hasH) {
      for (int i = 0; i < n + m; i++) {
        a[i].tp1 ^= 1;
        a[i].tp2 ^= 1;
        if (a[i].tp1 > a[i].tp2)
          swap(a[i].tp1, a[i].tp2), swap(a[i].p1, a[i].p2);
      }
      swap(n, m);
    }
    handle();
    static int pos[MaxN + 1];
    for (int i = 1; i <= n; i++) pos[perR[i]] = i;
    for (int i = 1; i <= n; i++) perR[i] = pos[i];
    for (int i = 1; i <= m; i++) pos[perC[i]] = i;
    for (int i = 1; i <= m; i++) perC[i] = pos[i];
    if (!hasH) {
      for (int i = 1; i <= n; i++) printf("%d ", perR[i]);
      printf("\n");
      for (int i = 1; i <= m; i++) printf("%d ", perC[i]);
      printf("\n");
    } else {
      for (int i = 1; i <= m; i++) printf("%d ", perC[i]);
      printf("\n");
      for (int i = 1; i <= n; i++) printf("%d ", perR[i]);
      printf("\n");
    }
  } catch (no_solution_error &e) {
    cout << "No solution" << endl;
  }
  return 0;
}