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 = 100000 + 5;
const int tag[4][4] = {
    {-1, 5, 0, 1}, {-1, -1, 2, 3}, {-1, -1, -1, 4}, {-1, -1, -1, -1}};
int n, m, cnt[6], ans[2][N];
int trisize, tri[N << 2][4], len[N << 2], fail[N << 2], nxt[N << 2][4],
    q[N << 2];
bool vis[4][N];
pair<char, int> e[4][N], g[4][N];
vector<pair<char, int> > nowcycle, anscycle;
vector<vector<pair<char, int> > > achieve[N << 2];
inline void label(char& x) {
  x = (x == 'T') ? 0 : ((x == 'B') ? 1 : ((x == 'L') ? 2 : 3));
}
inline void mark(char& x, int& y, const pair<char, int>& t) {
  x = t.first;
  y = t.second;
}
inline void display(void) {
  puts("No solution");
  exit(0);
}
inline void addedge1(char x1, int y1, char x2, int y2) {
  label(x1);
  label(x2);
  if (x1 > x2) swap(x1, x2), swap(y1, y2);
  ++cnt[tag[x1][x2]];
  e[x1][y1] = make_pair(x2, y2);
  e[x2][y2] = make_pair(x1, y1);
}
inline void addedge2(char x1, int y1, char x2, int y2) {
  g[x1][y1] = make_pair(x2, y2);
  g[x2][y2] = make_pair(x1, y1);
}
inline bool validate(void) {
  vector<pair<char, int> >::iterator hd1;
  int hd2;
  for (int j = 0, k, L = anscycle.size(), state = 0; j < (L << 1); ++j) {
    for (state = nxt[state][anscycle[k = j % L].first]; len[state] > L;
         state = fail[state])
      ;
    if (len[state] == L && !achieve[state].empty()) {
      nowcycle = *achieve[state].rbegin();
      hd1 = nowcycle.begin();
      hd2 = (k + 1) % L;
      for (; hd1 != nowcycle.end(); ++hd1, (++hd2) %= L)
        if (hd1->first == 2 || hd1->first == 3)
          ans[0][anscycle[hd2].second] = hd1->second;
        else
          ans[1][anscycle[hd2].second] = hd1->second;
      achieve[state].pop_back();
      return 1;
    }
  }
  return 0;
}
inline void find_cycle1(char x, int y) {
  nowcycle.clear();
  int state = 0;
  for (; !vis[x][y];) {
    nowcycle.push_back(make_pair(x, y));
    if (!tri[state][x]) tri[state][x] = ++trisize;
    state = tri[state][x];
    vis[x][y] = 1;
    if (vis[e[x][y].first][e[x][y].second])
      x ^= 1;
    else
      mark(x, y, e[x][y]);
  }
  achieve[state].push_back(nowcycle);
}
inline bool find_cycle2(char x, int y) {
  anscycle.clear();
  int state = 0;
  for (; !vis[x][y];) {
    anscycle.push_back(make_pair(x, y));
    vis[x][y] = 1;
    if (vis[g[x][y].first][g[x][y].second])
      x ^= 1;
    else
      mark(x, y, g[x][y]);
  }
  if (validate()) return 1;
  reverse(anscycle.begin(), anscycle.end());
  if (validate()) return 1;
  return 0;
}
inline void Aho_Corasick(void) {
  for (int l = 1, r = 1, state, i, j; l <= r; ++l) {
    for (state = q[l], i = 0; i < 4; ++i)
      if (tri[state][i])
        q[++r] = nxt[state][i] = tri[state][i],
        len[tri[state][i]] = len[state] + 1;
    if (!state) continue;
    for (i = 0; i < 4; ++i) {
      j = fail[state];
      if (j && !nxt[j][i]) j = 0;
      if (!tri[state][i])
        nxt[state][i] = nxt[j][i];
      else
        fail[tri[state][i]] = nxt[j][i];
    }
  }
}
inline void constructive(void) {
  for (int i = 1; i <= cnt[0]; ++i) addedge2(0, i, 2, i);
  for (int i = 1; i <= cnt[1]; ++i) addedge2(0, m - i + 1, 3, i);
  for (int i = 1; i <= cnt[2]; ++i) addedge2(1, i, 2, n - i + 1);
  for (int i = 1; i <= cnt[3]; ++i) addedge2(1, m - i + 1, 3, n - i + 1);
  for (int i = 1; i <= cnt[4]; ++i) addedge2(2, cnt[0] + i, 3, cnt[1] + i);
  for (int i = 1; i <= cnt[5]; ++i) addedge2(0, cnt[0] + i, 1, cnt[2] + i);
  memset(vis, 0, sizeof vis);
  for (int i = 1; i <= n; ++i) {
    if (!vis[2][i])
      if (!find_cycle2(2, i)) display();
    if (!vis[3][i])
      if (!find_cycle2(3, i)) display();
  }
  for (int i = 1; i <= m; ++i) {
    if (!vis[0][i])
      if (!find_cycle2(0, i)) display();
    if (!vis[1][i])
      if (!find_cycle2(1, i)) display();
  }
  for (int i = 1; i <= n; ++i) printf("%d%c", ans[0][i], i == n ? '\n' : ' ');
  for (int i = 1; i <= m; ++i) printf("%d%c", ans[1][i], i == m ? '\n' : ' ');
}
int main(int argc, char** argv) {
  char x1, x2;
  int y1, y2;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n + m; ++i) {
    for (; !isupper(x1 = getchar());)
      ;
    for (; !isupper(x2 = getchar());)
      ;
    scanf("%d%d", &y1, &y2);
    addedge1(x1, y1, x2, y2);
  }
  if (cnt[4] && cnt[5]) display();
  if (cnt[0] != cnt[3] || cnt[1] != cnt[2]) display();
  for (int i = 1; i <= n; ++i) {
    if (!vis[2][i]) find_cycle1(2, i);
    if (!vis[3][i]) find_cycle1(3, i);
  }
  for (int i = 1; i <= m; ++i) {
    if (!vis[0][i]) find_cycle1(0, i);
    if (!vis[1][i]) find_cycle1(1, i);
  }
  Aho_Corasick();
  constructive();
  return 0;
}