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 bs1 = 17680321;
const int bs2 = 19260817;
const int bs3 = 19491001;
int n, m, LR, BT, LT, TR, RB, BL, a[400100], col[400100], p;
bool vis[400100];
vector<int> v[400100], u[400100];
char s[10];
void V(int x, int y) { v[x].push_back(y), v[y].push_back(x); }
void U(int x, int y) { u[x].push_back(y), u[y].push_back(x); }
struct circ {
  int st, nx, len, bs1, bs2, bs3;
  circ(int A, int B, int C, int D, int E, int F) {
    st = A, nx = B, len = C, bs1 = D, bs2 = E, bs3 = F;
  }
  friend bool operator<(const circ& x, const circ& y) {
    if (x.len != y.len) return x.len < y.len;
    if (x.bs1 != y.bs1) return x.bs1 < y.bs1;
    if (x.bs2 != y.bs2) return x.bs2 < y.bs2;
    return x.bs3 < y.bs3;
  }
};
vector<circ> uu, vv;
circ HS() {
  int i = 0, j = 1, k = 0;
  while (i < p && j < p && k < p) {
    if (col[a[(i + k) % p]] == col[a[(j + k) % p]])
      k++;
    else {
      if (col[a[(i + k) % p]] > col[a[(j + k) % p]])
        i += k + 1;
      else
        j += k + 1;
      if (i == j) i++;
      k = 0;
    }
  }
  int I = p - min(i, j) - 1;
  i = 0, j = 1, k = 0;
  reverse(a, a + p);
  while (i < p && j < p && k < p) {
    if (col[a[(i + k) % p]] == col[a[(j + k) % p]])
      k++;
    else {
      if (col[a[(i + k) % p]] > col[a[(j + k) % p]])
        i += k + 1;
      else
        j += k + 1;
      if (i == j) i++;
      k = 0;
    }
  }
  int J = min(i, j);
  for (k = 0; k < p; k++) {
    if (col[a[(I + p - k) % p]] == col[a[(J + k) % p]]) continue;
    if (col[a[(I + p - k) % p]] < col[a[(J + k) % p]]) {
      int r1 = 0, r2 = 0, r3 = 0;
      for (k = 0; k < p; k++) {
        r1 = (4 * r1 + col[a[(I + p - k) % p]]) % bs1;
        r2 = (4 * r2 + col[a[(I + p - k) % p]]) % bs2;
        r3 = (4 * r3 + col[a[(I + p - k) % p]]) % bs3;
      }
      return circ(a[I], a[(I + p - 1) % p], p, r1, r2, r3);
    } else {
      int r1 = 0, r2 = 0, r3 = 0;
      for (k = 0; k < p; k++) {
        r1 = (4 * r1 + col[a[(J + k) % p]]) % bs1;
        r2 = (4 * r2 + col[a[(J + k) % p]]) % bs2;
        r3 = (4 * r3 + col[a[(J + k) % p]]) % bs3;
      }
      return circ(a[J], a[(J + 1) % p], p, r1, r2, r3);
    }
  }
  int r1 = 0, r2 = 0, r3 = 0;
  for (k = 0; k < p; k++) {
    r1 = (4 * r1 + col[a[(I + p - k) % p]]) % bs1;
    r2 = (4 * r2 + col[a[(I + p - k) % p]]) % bs2;
    r3 = (4 * r3 + col[a[(I + p - k) % p]]) % bs3;
  }
  return circ(a[I], a[(I + p - 1) % p], p, r1, r2, r3);
}
void dfs(vector<int>* w, int x) {
  if (vis[x]) return;
  vis[x] = true, a[p++] = x;
  for (auto y : w[x]) dfs(w, y);
}
int UU[100100], VV[100100];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) col[i] = 0;
  for (int i = n + 1; i <= n + m; i++) col[i] = 1;
  for (int i = n + m + 1; i <= 2 * n + m; i++) col[i] = 2;
  for (int i = 2 * n + m + 1; i <= 2 * n + 2 * m; i++) col[i] = 3;
  for (int i = 1, x, y; i <= n + m; i++) {
    scanf("%s%s%d%d", s, s + 1, &x, &y);
    if (s[0] == 'L') x += 0;
    if (s[0] == 'T') x += n;
    if (s[0] == 'R') x += n + m;
    if (s[0] == 'B') x += 2 * n + m;
    if (s[1] == 'L') y += 0;
    if (s[1] == 'T') y += n;
    if (s[1] == 'R') y += n + m;
    if (s[1] == 'B') y += 2 * n + m;
    V(x, y);
    if (s[0] == 'L' && s[1] == 'R' || s[1] == 'L' && s[0] == 'R') LR++;
    if (s[0] == 'B' && s[1] == 'T' || s[1] == 'B' && s[0] == 'T') BT++;
    if (s[0] == 'L' && s[1] == 'T' || s[1] == 'L' && s[0] == 'T')
      LT++, U(LT, n + LT);
    if (s[0] == 'T' && s[1] == 'R' || s[1] == 'T' && s[0] == 'R')
      TR++, U(n + m - TR + 1, n + m + TR);
    if (s[0] == 'R' && s[1] == 'B' || s[1] == 'R' && s[0] == 'B')
      RB++, U(2 * n + m - RB + 1, 2 * n + 2 * m - RB + 1);
    if (s[0] == 'B' && s[1] == 'L' || s[1] == 'B' && s[0] == 'L')
      BL++, U(2 * n + m + BL, n - BL + 1);
  }
  if (LR && BT) return puts("No solution"), 0;
  for (int i = 1; i <= LR; i++) U(LT + i, n + m + TR + i);
  for (int i = 1; i <= BT; i++) U(n + LT + i, 2 * n + m + BL + i);
  for (int i = 1; i <= n; i++) V(i, n + m + i), U(i, n + m + i);
  for (int i = n + 1; i <= n + m; i++) V(i, n + m + i), U(i, n + m + i);
  memset(vis, false, sizeof(vis));
  for (int i = 1; i <= 2 * n + 2 * m; i++) {
    if (vis[i]) continue;
    p = 0, dfs(v, i);
    vv.push_back(HS());
  }
  memset(vis, false, sizeof(vis));
  for (int i = 1; i <= 2 * n + 2 * m; i++) {
    if (vis[i]) continue;
    p = 0, dfs(u, i);
    uu.push_back(HS());
  }
  sort(vv.begin(), vv.end());
  sort(uu.begin(), uu.end());
  if (vv.size() != uu.size()) return puts("No solution"), 0;
  for (int i = 0; i < vv.size(); i++)
    if (vv[i] < uu[i] || uu[i] < vv[i]) return puts("No solution"), 0;
  for (int i = 0; i < vv.size(); i++) {
    int x = vv[i].st, y = uu[i].st;
    int X = v[x][0] ^ v[x][1] ^ vv[i].nx;
    int Y = u[y][0] ^ u[y][1] ^ uu[i].nx;
    for (int j = 0; j < vv[i].len; j++, X = v[x][0] ^ v[x][1] ^ X,
             Y = u[y][0] ^ u[y][1] ^ Y, swap(x, X), swap(y, Y)) {
      if (col[x] == 0) UU[y] = x;
      if (col[x] == 1) VV[y - n] = x - n;
      if (col[x] == 2) UU[y - n - m] = x - n - m;
      if (col[x] == 3) VV[y - 2 * n - m] = x - 2 * n - m;
    }
  }
  for (int i = 1; i <= n; i++) printf("%d ", UU[i]);
  puts("");
  for (int i = 1; i <= m; i++) printf("%d ", VV[i]);
  puts("");
  return 0;
}