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 N = 100010;
int now, c, d, tot, size, cnt, got, n, m, pos[6];
bool v[4][N];
int ans[2][N];
int T[N << 2][4], f[N << 2][4], Pi[N << 2], que[N << 2];
vector<int> have[N << 2];
vector<pair<int, int> > step[N];
inline void read(int &ret) {
  ret = 0;
  static char x;
  for (x = getchar(); x < '0' || x > '9'; x = getchar())
    ;
  while (x >= '0' && x <= '9') {
    ret = ret * 10 + x - '0';
    x = getchar();
  }
}
struct Res {
  pair<int, int> e[4][N], data[N << 2];
  int now, r1, t, ex[4];
  vector<pair<int, int> >::iterator r2;
  void addedge(int a, int b, int c, int d) {
    e[a][b] = make_pair(c, d);
    e[c][d] = make_pair(a, b);
  }
  bool Go() {
    now = 0;
    for (int i = 0; i < 2; ++i)
      for (int j = 0; j < got; ++j) {
        now = f[now][data[j].first];
        if ((j & 1) && !have[now].empty()) {
          t = *have[now].rbegin();
          if (step[t].size() != got) continue;
          have[now].pop_back();
          r1 = (j + 1) % got;
          r2 = step[t].begin();
          for (int order = 1; r2 != step[t].end();
               ++r2, r1 = (r1 + 1) % got, order ^= 1)
            if (order) ans[ex[data[r1].first]][data[r1].second] = r2->second;
          return 1;
        }
      }
    return 0;
  }
  bool work(int a, int b) {
    got = 0;
    do {
      data[got++] = make_pair(a, b);
      v[a][b] = 1;
      if (!v[a ^ 1][b])
        a ^= 1;
      else
        c = e[a][b].first, d = e[a][b].second, a = c, b = d;
    } while (!v[a][b]);
    if (Go()) return 1;
    reverse(data, data + got);
    if (Go()) return 1;
    return 0;
  }
  bool Compare() {
    for (int i = 1; i <= pos[0]; ++i) addedge(3, i, 0, i);
    for (int i = 1; i <= pos[1]; ++i) addedge(0, m - i + 1, 2, i);
    for (int i = 1; i <= pos[2]; ++i) addedge(1, m - i + 1, 2, n - i + 1);
    for (int i = 1; i <= pos[3]; ++i) addedge(3, n - i + 1, 1, i);
    for (int i = 1; i <= pos[5]; ++i) addedge(3, i + pos[0], 2, i + pos[1]);
    for (int i = 1; i <= pos[4]; ++i) addedge(0, i + pos[0], 1, i + pos[3]);
    ex[0] = ex[1] = 1;
    ex[2] = ex[3] = 0;
    memset(v, 0, sizeof(v));
    for (int i = 1; i <= n; ++i) {
      if (!v[3][i])
        if (!work(3, i)) return 0;
      if (!v[2][i])
        if (!work(2, i)) return 0;
    }
    for (int i = 1; i <= m; ++i) {
      if (!v[0][i])
        if (!work(0, i)) return 0;
      if (!v[1][i])
        if (!work(1, i)) return 0;
    }
    return 1;
  }
} Result;
struct Now {
  pair<int, int> e[4][N];
  int ex[260], place[4][4];
  void addedge(int a, int b, int c, int d) {
    e[a][b] = make_pair(c, d);
    e[c][d] = make_pair(a, b);
  }
  void Insert(int a, int b) {
    now = 0;
    do {
      step[tot].push_back(make_pair(a, b));
      if (!T[now][a]) T[now][a] = ++size;
      now = T[now][a];
      v[a][b] = 1;
      if (!v[a ^ 1][b])
        a ^= 1;
      else
        c = e[a][b].first, d = e[a][b].second, a = c, b = d;
    } while (!v[a][b]);
    have[now].push_back(tot++);
  }
  void Aho_Corasick() {
    for (int head = 1, tail = 1, x, u, k, i; head <= tail; ++head) {
      u = que[head];
      for (i = 0; i < 4; ++i)
        if (T[u][i]) f[u][i] = que[++tail] = T[u][i];
      if (!u) continue;
      for (i = 0; i < 4; ++i) {
        k = Pi[u];
        while (k && !T[k][i]) k = Pi[k];
        if ((x = T[u][i]))
          Pi[x] = T[k][i];
        else
          f[u][i] = T[k][i];
      }
    }
  }
  bool Init() {
    ex['T'] = 0;
    ex['B'] = 1;
    ex['R'] = 2;
    ex['L'] = 3;
    place[0][3] = 0;
    place[0][2] = 1;
    place[1][2] = 2;
    place[1][3] = 3;
    place[0][1] = 4;
    place[2][3] = 5;
    scanf("%d%d", &n, &m);
    for (int i = 0, a, b, p, q; i < n + m; ++i) {
      for (a = getchar(); !ex[a] && a != 'T'; a = getchar())
        ;
      for (b = getchar(); !ex[b] && b != 'T'; b = getchar())
        ;
      read(p);
      read(q);
      a = ex[a];
      b = ex[b];
      if (a > b) {
        swap(a, b);
        swap(p, q);
      }
      addedge(a, p, b, q);
      pos[place[a][b]]++;
    }
    if (pos[4] && pos[5]) return 0;
    if (pos[3] != pos[1] || pos[0] != pos[2]) return 0;
    for (int i = 1; i <= n; ++i) {
      if (!v[3][i]) Insert(3, i);
      if (!v[2][i]) Insert(2, i);
    }
    for (int i = 1; i <= m; ++i) {
      if (!v[0][i]) Insert(0, i);
      if (!v[1][i]) Insert(1, i);
    }
    Aho_Corasick();
    return 1;
  }
} Now_Work;
int main() {
  if (Now_Work.Init())
    if (Result.Compare()) {
      for (int i = 1; i <= n; ++i) printf("%d ", ans[0][i]);
      printf("\n");
      for (int i = 1; i <= m; ++i) printf("%d ", ans[1][i]);
      return 0;
    }
  printf("No solution");
  return 0;
}