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;
unsigned long long val1[400010], val2[400010], Power[400010 * 2],
    sum[400010 * 2];
vector<int> p1[400010], p2[400010];
int n, m, s[10][10], nC1, nC2, go[400010];
bool cmp1(int i, int j) { return val1[i] < val1[j]; }
bool cmp2(int i, int j) { return val2[i] < val2[j]; }
void Fail() {
  printf("No solution\n");
  exit(0);
}
void make(int a, int b) { go[a] = b, go[b] = a; }
int ID1(int x, int y) {
  if (x <= 2) return (x - 1) * n + y;
  return 2 * n + (x - 3) * m + y;
}
pair<int, int> ID2(int p) {
  if (p <= 2 * n) return make_pair((p - 1 + n) / n, (p - 1) % n + 1);
  return make_pair(2 + (p - 2 * n - 1 + m) / m, (p - 2 * n - 1) % m + 1);
}
int trans(char p) {
  if (p == 'L') return 1;
  if (p == 'R') return 2;
  if (p == 'T') return 3;
  return 4;
}
void read() {
  scanf("%d %d", &n, &m);
  char c1, c2;
  int a, b;
  for (int i = 1; i <= n + m; ++i) {
    for (c1 = getchar(); !isalpha(c1); c1 = getchar())
      ;
    for (c2 = getchar(); !isalpha(c2); c2 = getchar())
      ;
    scanf("%d", &a);
    scanf("%d", &b);
    int ida = trans(c1), idb = trans(c2);
    make(ID1(ida, a), ID1(idb, b));
    make(ID1(idb, b), ID1(ida, a));
    if (ida > idb) swap(ida, idb);
    ++s[ida][idb];
  }
}
unsigned long long gethash(int l, int r) {
  return sum[r] - sum[l - 1] * Power[r - l + 1];
}
bool cmp(int l1, int l2, int n, int *a) {
  int l = 1, r = n;
  while (l < r) {
    int mid = (l + r) >> 1;
    gethash(l1, l1 + mid - 1) == gethash(l2, l2 + mid - 1) ? l = mid + 1
                                                           : r = mid;
  }
  return a[l1 + l - 1] < a[l2 + l - 1];
}
int getmin(int *a, int n) {
  for (int i = 1; i <= n * 2; ++i) sum[i] = sum[i - 1] * 101 + a[i];
  int ans = 1;
  for (int i = 2; i <= n; ++i)
    if (gethash(ans, ans + n - 1) != gethash(i, i + n - 1) && cmp(i, ans, n, a))
      ans = i;
  return ans;
}
bool cmp(int *a, int *b, int n) {
  for (int i = 1; i <= n; ++i)
    if (a[i] != b[i]) return a[i] < b[i];
  return true;
}
void GetHash(unsigned long long *v, int &tot, vector<int> *p) {
  static bool use[400010];
  static int a[400010 * 2], b[400010 * 2], ta[400010 * 2], tb[400010 * 2];
  memset(use, false, sizeof(use));
  for (int i = 1; i <= n + n + m + m; ++i)
    if (!use[i]) {
      int j = i, k, t = 0;
      do {
        use[j] = true;
        a[++t] = ID2(j).first, b[t] = j;
        k = go[j], use[k] = true;
        pair<int, int> vk = ID2(k);
        a[++t] = vk.first, b[t] = k;
        vk.first += vk.first & 1 ? 1 : -1;
        j = ID1(vk.first, vk.second);
      } while (j != i);
      for (int j = 1; j <= t; ++j) ta[j] = a[t - j + 1], tb[j] = b[t - j + 1];
      for (int j = t + 1; j <= t + t; ++j)
        a[j] = a[j - t], b[j] = b[j - t], ta[j] = ta[j - t], tb[j] = tb[j - t];
      int id1 = getmin(a, t), id2 = getmin(ta, t);
      if (cmp(a + id1 - 1, ta + id2 - 1, t)) {
        ++tot;
        for (int j = id1; j < id1 + t; ++j)
          v[tot] = v[tot] * 101 + a[j], p[tot].push_back(b[j]);
      } else {
        ++tot;
        for (int j = id2; j < id2 + t; ++j)
          v[tot] = v[tot] * 101 + ta[j], p[tot].push_back(tb[j]);
      }
    }
}
void print() {
  if (s[1][2] && s[3][4]) Fail();
  if (s[1][3] != s[2][4]) Fail();
  if (s[1][4] != s[2][3]) Fail();
  GetHash(val1, nC1, p1);
  for (int i = 1; i <= s[1][3]; ++i)
    make(ID1(1, i), ID1(3, i)), make(ID1(3, i), ID1(1, i));
  for (int i = 1; i <= s[2][3]; ++i)
    make(ID1(2, i), ID1(3, m - i + 1)), make(ID1(3, m - i + 1), ID1(2, i));
  for (int i = 1; i <= s[1][4]; ++i)
    make(ID1(1, n - i + 1), ID1(4, i)), make(ID1(4, i), ID1(1, n - i + 1));
  for (int i = 1; i <= s[2][4]; ++i)
    make(ID1(2, n - i + 1), ID1(4, m - i + 1)),
        make(ID1(4, m - i + 1), ID1(2, n - i + 1));
  for (int i = 1; i <= s[1][2]; ++i)
    make(ID1(1, s[1][3] + i), ID1(2, s[2][3] + i)),
        make(ID1(2, s[2][3] + i), ID1(1, s[1][3] + i));
  for (int i = 1; i <= s[3][4]; ++i)
    make(ID1(3, s[1][3] + i), ID1(4, s[1][4] + i)),
        make(ID1(4, s[1][4] + i), ID1(3, s[1][3] + i));
  GetHash(val2, nC2, p2);
  if (nC1 != nC2) Fail();
  static int id1[400010], id2[400010], ans1[400010], ans2[400010];
  for (int i = 1; i <= nC1; ++i) id1[i] = i, id2[i] = i;
  sort(id1 + 1, id1 + nC1 + 1, cmp1), sort(id2 + 1, id2 + nC2 + 1, cmp2);
  for (int i = 1; i <= nC1; ++i) {
    if (val1[id1[i]] != val2[id2[i]]) Fail();
    for (int j = 0; j < (int)p1[id1[i]].size(); ++j) {
      pair<int, int> t = ID2(p2[id2[i]][j]);
      if (t.first == 1) ans1[t.second] = ID2(p1[id1[i]][j]).second;
      if (t.first == 3) ans2[t.second] = ID2(p1[id1[i]][j]).second;
    }
  }
  for (int i = 1; i <= n; ++i) printf("%d%c", ans1[i], i < n ? ' ' : '\n');
  for (int i = 1; i <= m; ++i) printf("%d%c", ans2[i], i < m ? ' ' : '\n');
}
void Prepare() {
  Power[0] = 1;
  for (int i = 1; i <= n + n + m + m; ++i) Power[i] = Power[i - 1] * 101;
}
int main() {
  read();
  Prepare();
  print();
  return 0;
}