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 Inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3fll;
const int Maxn = 400005, ch = 233;
int n, m, nm;
int inline getid(char c) {
  return c == 'L' ? 0 : (c == 'T' ? 1 : (c == 'R' ? 2 : 3));
}
void inline shit() {
  puts("No solution");
  exit(0);
}
struct Graph_Zxbs {
  vector<int> nei[Maxn];
  bool lgl[Maxn];
  vector<int> tmp, ftmp;
  vector<vector<int> > hs;
  vector<pair<unsigned long long, int> > hsh;
  void inline addedge(int u, int v) {
    nei[u].push_back(v);
    nei[v].push_back(u);
  }
  void inline dfs(int now) {
    lgl[now] = 1;
    tmp.push_back(now);
    for (auto &to : (nei[now]))
      if (!lgl[to]) dfs(to);
  }
  void inline getZxbs(vector<int> &a) {
    int i = 0, j = 1, n = ((int)(a).size());
    while (j < n) {
      int k = 0;
      while (k < n && a[(i + k) % n] / nm == a[(j + k) % n] / nm) ++k;
      if (k == n) break;
      if (a[(i + k) % n] / nm > a[(j + k) % n] / nm) {
        i += k + 1;
        if (i <= j) i = j + 1;
        swap(i, j);
      } else
        j += k + 1;
    }
    vector<int> b;
    for (int j = 0; j < (n); ++j) b.push_back(a[(i + j) % n]);
    a.swap(b);
  }
  unsigned long long inline gethash(const vector<int> &a) {
    unsigned long long res = 0;
    for (auto &it : (a)) res = res * ch + it / nm;
    return res;
  }
  void inline getHuan() {
    for (int i = 0; i < (4 * nm); ++i)
      if (!lgl[i]) {
        tmp.clear();
        dfs(i);
        if (((int)(tmp).size()) == 1) continue;
        ftmp = tmp;
        reverse((ftmp).begin(), (ftmp).end());
        getZxbs(tmp);
        getZxbs(ftmp);
        for (int i = 0; i < (((int)(tmp).size())); ++i)
          if (tmp[i] / nm != ftmp[i] / nm) {
            if (tmp[i] > ftmp[i]) tmp.swap(ftmp);
            break;
          }
        hsh.emplace_back(gethash(tmp), ((int)(hs).size()));
        hs.push_back(tmp);
      }
    sort((hsh).begin(), (hsh).end());
  }
} g1, g2;
int cnt[4][4];
int px[Maxn], py[Maxn];
int main() {
  scanf("%d%d", &n, &m);
  nm = max(n, m);
  for (int i = 0; i < (n + m); ++i) {
    char p1, p2;
    int x1, x2;
    scanf(" %c %c %d%d", &p1, &p2, &x1, &x2);
    --x1;
    --x2;
    int f1 = getid(p1), f2 = getid(p2);
    ++cnt[f1][f2];
    ++cnt[f2][f1];
    g1.addedge(f1 * nm + x1, f2 * nm + x2);
  }
  if (cnt[0][2] && cnt[1][3]) shit();
  if (cnt[0][3] != cnt[1][2] || cnt[0][1] != cnt[2][3]) shit();
  for (int i = 0; i < (n); ++i)
    g1.addedge(0 * nm + i, 2 * nm + i), g2.addedge(0 * nm + i, 2 * nm + i);
  for (int i = 0; i < (m); ++i)
    g1.addedge(1 * nm + i, 3 * nm + i), g2.addedge(1 * nm + i, 3 * nm + i);
  for (int i = 0; i < (cnt[0][1]); ++i) g2.addedge(0 * nm + i, 1 * nm + i);
  for (int i = 0; i < (cnt[2][3]); ++i)
    g2.addedge(2 * nm + (n - i - 1), 3 * nm + (m - i - 1));
  for (int i = 0; i < (cnt[0][3]); ++i)
    g2.addedge(0 * nm + (n - i - 1), 3 * nm + i);
  for (int i = 0; i < (cnt[1][2]); ++i)
    g2.addedge(1 * nm + (m - i - 1), 2 * nm + i);
  for (int i = 0; i < (cnt[0][2]); ++i)
    g2.addedge(0 * nm + cnt[0][1] + i, 2 * nm + cnt[1][2] + i);
  for (int i = 0; i < (cnt[1][3]); ++i)
    g2.addedge(1 * nm + cnt[0][1] + i, 3 * nm + cnt[0][3] + i);
  g1.getHuan();
  g2.getHuan();
  if (((int)(g1.hs).size()) != ((int)(g2.hs).size())) shit();
  for (int i = 0; i < (((int)(g1.hs).size())); ++i)
    if (g1.hsh[i].first != g2.hsh[i].first) shit();
  for (int i = 0; i < (((int)(g1.hs).size())); ++i) {
    vector<int> &v1 = g1.hs[g1.hsh[i].second], &v2 = g2.hs[g2.hsh[i].second];
    for (int i = 0; i < (((int)(v1).size())); ++i) {
      if (v1[i] / nm == 0) px[v2[i] % nm] = v1[i] % nm;
      if (v1[i] / nm == 1) py[v2[i] % nm] = v1[i] % nm;
    }
  }
  for (int i = 0; i < (n); ++i) printf("%d%c", px[i] + 1, " \n"[i == n - 1]);
  for (int i = 0; i < (m); ++i) printf("%d%c", py[i] + 1, " \n"[i == m - 1]);
  return 0;
}