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 unsigned long long P = 323232323;
int N;
struct Graph {
  vector<int> G[400010];
  int vis[400010];
  vector<int> node;
  vector<vector<int> > data;
  vector<pair<unsigned long long, int> > all;
  Graph() { clear(); }
  void clear() {
    for (int i = 0; i < 400005; i++) G[i].clear();
  }
  void AddEdge(int x, int y) {
    G[x].push_back(y);
    G[y].push_back(x);
  }
  void dfs(int x) {
    vis[x] = 1, node.push_back(x);
    for (auto v : G[x]) {
      if (!vis[v]) dfs(v);
    }
  }
  void Flush(vector<int> &a) {
    int p1 = 0, p2 = 1;
    while (p2 < a.size()) {
      int k = 0;
      while (k < a.size() &&
             a[(p1 + k) % a.size()] / N == a[(p2 + k) % a.size()] / N)
        k++;
      if (k == a.size()) break;
      if (a[(p1 + k) % a.size()] / N > a[(p2 + k) % a.size()] / N) {
        p1 += k + 1;
        if (p1 <= p2) p1 = p2 + 1;
        swap(p1, p2);
      } else
        p2 += k + 1;
    }
    for (int i = 0; i < p1; i++) a.push_back(a[i]);
    a.erase(a.begin(), a.begin() + p1);
  }
  unsigned long long GetHash(const vector<int> &node) {
    unsigned long long H = 0;
    for (auto x : node) H = H * P + x / N;
    return H;
  }
  void GetAll() {
    memset(vis, 0, sizeof(vis));
    for (int i = 0; i < 4 * N; i++) {
      if (vis[i]) continue;
      node.clear(), dfs(i);
      if (node.size() == 1) continue;
      Flush(node);
      vector<int> tmp = node;
      reverse(tmp.begin(), tmp.end());
      Flush(tmp);
      for (int i = 0; i < node.size(); i++) {
        if (node[i] / N != tmp[i] / N) {
          if (node[i] > tmp[i]) node = tmp;
          break;
        }
      }
      all.push_back(make_pair(GetHash(node), (int)data.size()));
      data.push_back(node);
    }
    sort(all.begin(), all.end());
  }
} G1, G2;
int GetId(char c) { return c == 'L' ? 0 : c == 'T' ? 1 : c == 'R' ? 2 : 3; }
int cnt[4][4];
int px[100010], py[100010];
int main() {
  goto MAIN;
BAD:;
  printf("No solution\n");
  return 0;
MAIN:;
  int n, m;
  scanf("%d%d", &n, &m);
  N = max(n, m);
  for (int i = 0; i < n + m; i++) {
    char d1[2], d2[2];
    int x, y;
    scanf("%s%s%d%d", d1, d2, &x, &y), x--, y--;
    int id1 = GetId(d1[0]), id2 = GetId(d2[0]);
    cnt[id1][id2]++, cnt[id2][id1]++;
    G1.AddEdge(id1 * N + x, id2 * N + y);
  }
  for (int i = 0; i < n; i++)
    G1.AddEdge(0 * N + i, 2 * N + i), G2.AddEdge(0 * N + i, 2 * N + i);
  for (int i = 0; i < m; i++)
    G1.AddEdge(1 * N + i, 3 * N + i), G2.AddEdge(1 * N + i, 3 * N + i);
  if (cnt[0][2] && cnt[1][3]) goto BAD;
  if (cnt[0][1] != cnt[2][3]) goto BAD;
  for (int i = 0; i < cnt[0][1]; i++) G2.AddEdge(0 * N + i, 1 * N + i);
  for (int i = 0; i < cnt[2][3]; i++)
    G2.AddEdge(2 * N + n - i - 1, 3 * N + m - i - 1);
  for (int i = 0; i < cnt[0][3]; i++) G2.AddEdge(0 * N + n - i - 1, 3 * N + i);
  for (int i = 0; i < cnt[2][1]; i++) G2.AddEdge(2 * N + i, 1 * N + m - i - 1);
  for (int i = 0; i < cnt[0][2]; i++)
    G2.AddEdge(0 * N + cnt[0][1] + i, 2 * N + cnt[2][1] + i);
  for (int i = 0; i < cnt[1][3]; i++)
    G2.AddEdge(1 * N + cnt[0][1] + i, 3 * N + cnt[0][3] + i);
  G1.GetAll();
  G2.GetAll();
  if (G1.all.size() != G2.all.size()) goto BAD;
  for (int i = 0; i < G1.all.size(); i++) {
    if (G1.all[i].first != G2.all[i].first) goto BAD;
  }
  for (int i = 0; i < G1.all.size(); i++) {
    const vector<int> &a = G1.data[G1.all[i].second],
                      &b = G2.data[G2.all[i].second];
    for (int j = 0; j < a.size(); j++) {
      int x = a[j], y = b[j];
      if (x / N == 0) px[y % N] = x % N;
      if (x / N == 1) py[y % N] = x % N;
    }
  }
  for (int i = 0; i < n; i++) printf("%d ", px[i] + 1);
  printf("\n");
  for (int i = 0; i < m; i++) printf("%d ", py[i] + 1);
  printf("\n");
  return 0;
}