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 = 410000;
bool zhuan;
int n, m;
int ans[MAXN];
int dui[MAXN], std_dui[MAXN];
int S, now, jian;
int fail[MAXN];
int line[MAXN], id[MAXN];
int N;
bool vis[MAXN];
int a[MAXN], b[MAXN];
inline void wei() {
  printf("No solution\n");
  exit(0);
}
inline int getreal(char a, int x) {
  if (zhuan) {
    if (a == 'L')
      a = 'T';
    else if (a == 'R')
      a = 'B';
    else if (a == 'B')
      a = 'R';
    else
      a = 'L';
  }
  if (a == 'T') return x;
  if (a == 'B') return x + m;
  if (a == 'L') return 2 * m + x;
  return 2 * m + n + x;
}
inline int type(char a, char b) {
  if (a == 'L') {
    if (b == 'R') wei();
    if (b == 'T')
      return 1;
    else
      return 3;
  }
  if (a == 'R') {
    if (b == 'L') wei();
    if (b == 'T')
      return 2;
    else
      return 4;
  }
  if (a == 'T') {
    if (b == 'B')
      return 5;
    else
      return type(b, a);
  }
  if (a == 'B') {
    if (b == 'T')
      return 5;
    else
      return type(b, a);
  }
}
char pos(int x) {
  if (x > 2 * m + n) return 'R';
  if (x > 2 * m) return 'L';
  if (x > m) return 'B';
  return 'T';
}
int point(int x) {
  if (pos(x) == 'T') return x;
  if (pos(x) == 'B') return x - m;
  if (pos(x) == 'L') return x - m;
  return x - m - n;
}
inline int type(int a, int b) { return type(pos(a), pos(b)); }
int num[6];
void Read() {
  scanf("%d%d", &n, &m);
  if (n > m) {
    swap(n, m);
    zhuan = 1;
  }
  for (int i = (1); i <= (int)n + m; i++) {
    int x, y;
    char a[2], b[2];
    scanf("%s%s%d%d", a + 1, b + 1, &x, &y);
    int u = getreal(a[1], x);
    int v = getreal(b[1], y);
    dui[u] = v;
    dui[v] = u;
  }
  for (int i = (1); i <= (int)2 * (n + m); i++) num[type(i, dui[i])]++;
  for (int i = (1); i <= (int)5; i++) num[i] /= 2;
  if (num[1] != num[4]) wei();
  if (num[2] != num[3]) wei();
  if (num[1] + num[3] != n) wei();
  S = now = min(num[1], num[2]);
  if (num[1] < num[2]) {
    jian = n - 2 * S;
  } else
    jian = 2 * S - n;
  for (int i = (num[1] + 1); i <= (int)m - num[2]; i++) {
    std_dui[i] = i + jian + m;
    std_dui[i + jian + m] = i;
  }
  for (int i = (1); i <= (int)num[1]; i++) {
    std_dui[i] = i + 2 * m;
    std_dui[i + 2 * m] = i;
    std_dui[2 * m - i + 1] = 2 * m + 2 * n - i + 1;
    std_dui[2 * m + 2 * n - i + 1] = 2 * m - i + 1;
  }
  for (int i = (1); i <= (int)num[2]; i++) {
    std_dui[m - i + 1] = 2 * m + n + i;
    std_dui[2 * m + n + i] = m - i + 1;
    std_dui[2 * m + n + 1 - i] = m + i;
    std_dui[m + i] = 2 * m + n + 1 - i;
  }
}
void KanMaoPian() {
  fail[0] = -1;
  int p;
  for (int i = (1); i <= (int)N; i++) {
    for (p = fail[i - 1]; p != -1 && line[p + 1] != line[i]; p = fail[p])
      ;
    fail[i] = p + 1;
  }
}
int papapa(int me, bool jabby, int *A, int *B) {
  int len = 0;
  int y = me, z;
  bool jabby_is_god = 1;
  while (jabby_is_god) {
    if (jabby)
      z = std_dui[y];
    else
      z = dui[y];
    A[++len] = type(y, z);
    B[len] = point(y);
    if (!jabby) vis[z] = 1;
    y = z;
    if (pos(y) == 'T')
      y += m;
    else if (pos(y) == 'B')
      y -= m;
    else if (pos(y) == 'L')
      y += n;
    else
      y -= n;
    if (!jabby) vis[y] = 1;
    if (y == me) break;
  }
  return len;
}
void dealwith(int s) {
  if (s != 4 && s != N) wei();
  if (s == 4 && a[1] == 1 && a[2] == 2 && a[3] == 4 && a[4] == 3) {
    if (!S) wei();
    ans[S] = b[1];
    ans[S + m] = b[2];
    ans[m - S + 1] = b[3];
    ans[n - S + 1 + m] = b[4];
    S--;
    return;
  }
  if (s == 4 && a[1] == 2 && a[2] == 1 && a[3] == 3 && a[4] == 4) {
    if (!S) wei();
    ans[m - S + 1] = b[1];
    ans[m + S] = b[2];
    ans[S] = b[3];
    ans[n - S + 1 + m] = b[4];
    S--;
    return;
  }
  if (s ^ N) wei();
  for (int i = (1); i <= (int)N; i++) a[i + N] = a[i], b[i + N] = b[i];
  int p = 0;
  for (int i = (1); i <= (int)2 * N; i++) {
    while (p != -1 && a[i] != line[p + 1]) p = fail[p];
    p++;
    if (p == N) {
      papapa(++now, 1, id, id);
      for (int j = (i - N + 1); j <= (int)i; j++)
        ans[id[j - (i - N + 1) + 1]] = b[j];
      return;
    }
  }
  wei();
}
void Work() {
  N = papapa(now + 1, 1, line, id);
  KanMaoPian();
  for (int i = (1); i <= (int)(n + m) * 2; i++)
    if (!vis[i]) {
      int Len = papapa(i, 0, a, b);
      dealwith(Len);
    }
}
void out() {
  if (S) wei();
  if (zhuan) {
    for (int i = (1); i <= (int)m; i++) printf("%d ", ans[i]);
    printf("\n");
    for (int i = (1); i <= (int)n; i++) printf("%d ", ans[i + m] - m);
  } else {
    for (int i = (1); i <= (int)n; i++) printf("%d ", ans[i + m] - m);
    printf("\n");
    for (int i = (1); i <= (int)m; i++) printf("%d ", ans[i]);
  }
}
int main() {
  Read();
  Work();
  out();
}