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;
int Read() {
  char c;
  while (c = getchar(), (c != '-') && (c < '0' || c > '9'))
    ;
  bool neg = (c == '-');
  int ret = (neg ? 0 : c - 48);
  while (c = getchar(), c >= '0' && c <= '9') ret = ret * 10 + c - 48;
  return neg ? -ret : ret;
}
const int MAXN = 400005;
map<char, char> mp;
int N, M, n, D, P, cyc, g[MAXN], lnk[MAXN], dir[MAXN], id[MAXN], pi[MAXN],
    td[MAXN << 1], ti[MAXN << 1], ans[MAXN], ct[6];
bool swapped, vis[MAXN];
char GetC() {
  char c;
  while (c = getchar(), (c != 'L') && (c != 'R') && (c != 'T') && (c != 'B'))
    ;
  return c;
}
int getID(char c, int x) {
  return (c == 'T' ? 0 : c == 'L' ? 2 * M : c == 'B' ? M : 2 * M + N) + x;
}
void OVER() {
  puts("No solution");
  exit(0);
}
int getType(char c1, char c2) {
  if ((c1 == 'L' && c2 == 'R') || (c2 == 'L' && c1 == 'R')) OVER();
  if (c1 == 'T') return (c2 == 'L' ? 1 : c2 == 'R' ? 2 : 5);
  if (c1 == 'B') return (c2 == 'L' ? 3 : c2 == 'R' ? 4 : 5);
  if (c1 == 'L') return (c2 == 'B' ? 3 : 1);
  return (c2 == 'B' ? 4 : 2);
}
char getSide(int x) {
  if (x <= M) return 'T';
  if (x <= 2 * M) return 'B';
  return x > 2 * M + N ? 'R' : 'L';
}
int getNo(int x) {
  return x - (getSide(x) == 'T' ? 0 : M + (getSide(x) == 'R' ? N : 0));
}
void init() {
  scanf("%d%d", &N, &M);
  if (N > M) {
    mp['L'] = 'T', mp['T'] = 'L', mp['R'] = 'B', mp['B'] = 'R';
    swap(N, M), swapped = 1;
  }
  for (int i = 1; i <= N + M; i++) {
    char c1 = GetC(), c2 = GetC();
    if (swapped) c1 = mp[c1], c2 = mp[c2];
    ++ct[getType(c1, c2)];
    int u = Read(), v = Read();
    int x = getID(c1, u), y = getID(c2, v);
    g[x] = y, g[y] = x;
  }
}
void Link(int x, int y) { lnk[x] = y, lnk[y] = x; }
int FindCyc(int src, int *dir, int *id, bool v) {
  int x = src, cnt = 0, y;
  for (;;) {
    y = v ? lnk[x] : g[x];
    dir[++cnt] = getType(getSide(x), getSide(y)), id[cnt] = getNo(x);
    x = y;
    if (!v) vis[x] = 1;
    if (getSide(x) == 'T')
      x += M;
    else if (getSide(x) == 'B')
      x -= M;
    else if (getSide(x) == 'L')
      x += N;
    else
      x -= N;
    if (!v) vis[x] = 1;
    if (x == src) return cnt;
  }
}
void KMP() {
  pi[0] = -1;
  for (int i = 1; i <= cyc; i++) {
    int k = pi[i - 1];
    while (k >= 0 && dir[i] != dir[k + 1]) k = pi[k];
    pi[i] = ++k;
  }
}
void SolveCyc(int src) {
  int len = FindCyc(src, td, ti, 0);
  if (len == 4) {
    if (td[1] == 1 && td[2] == 2 && td[3] == 4 && td[4] == 3) {
      if (!n) OVER();
      ans[n] = ti[1], ans[n + M] = ti[2], ans[M - n + 1] = ti[3],
      ans[M + N - n + 1] = ti[4];
      --n;
      return;
    }
    if (td[1] == 2 && td[2] == 1 && td[3] == 3 && td[4] == 4) {
      if (!n) OVER();
      ans[n] = ti[3], ans[n + M] = ti[2], ans[M - n + 1] = ti[1],
      ans[M + N - n + 1] = ti[4];
      --n;
      return;
    }
  }
  if (len != cyc) OVER();
  for (int i = 1; i <= len; i++) td[i + len] = td[i], ti[i + len] = ti[i];
  int k = 0;
  for (int i = 1; i <= len + len; i++) {
    while (k >= 0 && dir[k + 1] != td[i]) k = pi[k];
    if (++k == len) {
      FindCyc(++P, id, id, 1);
      for (int j = i - len + 1; j <= i; j++) ans[id[j - i + len]] = ti[j];
      return;
    }
  }
  OVER();
}
void work() {
  if (ct[1] != ct[4] || ct[2] != ct[3] || ct[1] + ct[2] != N) OVER();
  if (ct[1] < ct[2])
    n = ct[1], D = N - 2 * n;
  else
    n = ct[2], D = 2 * n - N;
  P = n;
  for (int i = 1; i <= ct[1]; i++)
    Link(i, 2 * M + i), Link(2 * M + 1 - i, 2 * (N + M) + 1 - i);
  for (int i = 1; i <= ct[2]; i++)
    Link(M + i, 2 * M + N + 1 - i), Link(M + 1 - i, 2 * M + N + i);
  for (int i = ct[1] + 1; i <= M - ct[2]; i++) Link(i, i + D + M);
  cyc = FindCyc(P + 1, dir, id, 1);
  KMP();
  for (int i = 1; i <= 2 * (N + M); i++)
    if (!vis[i]) SolveCyc(i);
  if (n) OVER();
  if (swapped) {
    for (int i = 1; i <= M; i++) printf("%d%c", ans[i], i < M ? ' ' : '\n');
    for (int i = 1; i <= N; i++)
      printf("%d%c", ans[i + M] - M, i < N ? ' ' : '\n');
  } else {
    for (int i = 1; i <= N; i++)
      printf("%d%c", ans[i + M] - M, i < N ? ' ' : '\n');
    for (int i = 1; i <= M; i++) printf("%d%c", ans[i], i < M ? ' ' : '\n');
  }
}
int main() {
  init();
  work();
  return 0;
}