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 double pi = acos(-1);
bool rota;
int n, m, S, V, N;
int per[410000], E[410000], good_E[410000], vis[410000], a[410000 * 2],
    b[410000 * 2], pattern[410000], id[410000], fail[410000], debug[410000];
void END() {
  printf("No solution\n");
  exit(0);
}
int ch(char c, int x) {
  if (rota) {
    if (c == 'L')
      c = 'T';
    else if (c == 'B')
      c = 'R';
    else if (c == 'R')
      c = 'B';
    else
      c = 'L';
  }
  return (c == 'T' ? 0 : c == 'L' ? 2 * m : c == 'B' ? m : 2 * m + n) + x;
}
char dir(int x) {
  if (x >= 1 && x <= m) return 'T';
  if (x > 2 * m && x <= 2 * m + n) return 'L';
  if (x > m && x <= 2 * m) return 'B';
  if (x > 2 * m + n) return 'R';
}
int gettype(int x, int y) {
  if (dir(x) == 'T' && dir(y) == 'L') return 1;
  if (dir(x) == 'T' && dir(y) == 'R') return 2;
  if (dir(x) == 'L' && dir(y) == 'B') return 3;
  if (dir(x) == 'R' && dir(y) == 'B') return 4;
  if (dir(x) == 'T' && dir(y) == 'B') return 5;
  if (dir(x) == 'L' && dir(y) == 'R') END();
  return gettype(y, x);
}
int getnum(int x) {
  if (dir(x) == 'T') return x;
  if (dir(x) == 'B') return x - m;
  if (dir(x) == 'L') return x - m;
  return x - m - n;
}
void init() {
  scanf("%d%d", &n, &m);
  if (n > m) {
    swap(n, m);
    rota = 1;
  }
  for (int i = 1; i <= n + m; ++i) {
    char c1, c2;
    int x1, x2;
    scanf("\n%c %c%d%d", &c1, &c2, &x1, &x2);
    int u = ch(c1, x1), v = ch(c2, x2);
    E[u] = v;
    E[v] = u;
  }
}
void print() {
  if (S) END();
  if (rota) {
    for (int i = 1; i <= m; ++i) printf("%d ", per[i]);
    puts("");
    for (int i = 1; i <= n; ++i) printf("%d ", per[i + m] - m);
  } else {
    for (int i = 1; i <= n; ++i) printf("%d ", per[i + m] - m);
    puts("");
    for (int i = 1; i <= m; ++i) printf("%d ", per[i]);
  }
}
void link_good(int x, int y) {
  assert(good_E[x] == 0);
  assert(good_E[y] == 0);
  good_E[x] = y;
  good_E[y] = x;
}
int Search(int x, bool good, int *p1, int *p2) {
  int y = x, tot, z;
  tot = 0;
  for (;;) {
    if (good) {
      z = good_E[y];
    } else
      z = E[y];
    p1[++tot] = gettype(y, z);
    p2[tot] = getnum(y);
    if (!good) vis[z] = 1;
    y = z;
    if (dir(y) == 'T')
      y += m;
    else if (dir(y) == 'B')
      y -= m;
    else if (dir(y) == 'L')
      y += n;
    else
      y -= n;
    if (!good) vis[y] = 1;
    if (y == x) break;
  }
  return tot;
}
void prep_kmp() {
  int p;
  fail[0] = -1;
  for (int i = 1; i <= N; ++i) {
    for (p = fail[i - 1]; p != -1 && pattern[i] != pattern[p + 1]; p = fail[p])
      ;
    fail[i] = ++p;
  }
}
void solve_circle(int s) {
  if (s != 4 && s != N) END();
  if (s == 4 && a[1] == 1 && a[2] == 2 && a[3] == 4 && a[4] == 3) {
    if (!S) END();
    per[S] = b[1];
    per[S + m] = b[2];
    per[m - S + 1] = b[3];
    per[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) END();
    per[m - S + 1] = b[1];
    per[S + m] = b[2];
    per[S] = b[3];
    per[n - S + 1 + m] = b[4];
    S--;
    return;
  }
  if (s != N) END();
  for (int i = 1; i <= N; ++i) a[i + N] = a[i], b[i + N] = b[i];
  int p = 0;
  for (int i = 1; i <= N + N; ++i) {
    while (p != -1 && a[i] != pattern[p + 1]) p = fail[p];
    p++;
    if (p == N) {
      Search(++V, 1, id, id);
      for (int j = i - N + 1; j <= i; ++j) per[id[j - (i - N + 1) + 1]] = b[j];
      return;
    }
  }
  END();
}
void work() {
  int s[6] = {0}, D;
  for (int i = 1; i <= 2 * (m + n); ++i) s[gettype(i, E[i])]++;
  if (s[1] != s[4] || s[2] != s[3] || s[1] + s[2] != n * 2) END();
  S = min(s[1], s[2]) / 2;
  V = S;
  if (s[1] < s[2])
    D = n - 2 * S;
  else
    D = -(n - 2 * S);
  for (int i = s[1] / 2 + 1; i <= m - s[2] / 2; ++i) link_good(i, i + D + m);
  for (int i = 1; i <= s[1] / 2; ++i) {
    link_good(2 * m + i, i);
    link_good(2 * m + 1 - i, 2 * (n + m) + 1 - i);
  }
  for (int i = 1; i <= s[2] / 2; ++i) {
    link_good(2 * m + n + 1 - i, m + i);
    link_good(m + 1 - i, 2 * m + n + i);
  }
  N = Search(V + 1, 1, pattern, id);
  prep_kmp();
  for (int i = 1; i <= 2 * (n + m); ++i)
    if (!vis[i]) {
      int s = Search(i, 0, a, b);
      solve_circle(s);
    }
}
int main() {
  init();
  work();
  print();
}