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 oo = 0x3f3f3f3f;
const int maxn = 100000, max0 = 10000000;
int n, m;
pair<int, int> link[4][maxn + 5];
int cnt[4][4];
int id[256];
int ans[2][maxn + 5];
bool has[2];
int len[4];
int Mod0, Mod1, lucky;
pair<pair<int, int>, vector<pair<int, int> > > yyt[maxn + 5];
int pos0[maxn + 5];
int pig = 0;
pair<pair<int, int>, vector<pair<int, int> > > lyc[maxn + 5];
int pos1[maxn + 5];
int orz = 0;
bool vis[4][maxn + 5] = {{0}};
int find_prime(const int &first, const int &second) {
pmxm:;
  static int tmp;
  tmp = first + ((long long)rand() * (RAND_MAX + 1) + rand()) % second;
  for (int i = 2; i * i <= tmp; ++i)
    if (!(tmp % i)) goto pmxm;
  return tmp;
}
bool cmp0(const int &first, const int &second) {
  return yyt[first].first < yyt[second].first;
}
bool cmp1(const int &first, const int &second) {
  return lyc[first].first < lyc[second].first;
}
int main() {
  srand(time(NULL));
  Mod0 = find_prime(1e9, 1e8), Mod1 = find_prime(Mod0 + 1, 1e8),
  lucky = find_prime(Mod1 + 1, 1e8);
  scanf("%d%d", &n, &m);
  id['L'] = 0, id['B'] = 1, id['R'] = 2, id['T'] = 3;
  len[0] = len[2] = n, len[1] = len[3] = m;
  for (int i = (0), _end_ = (n + m); i != _end_; ++i) {
    char from[2], to[2];
    scanf("%s%s", from, to);
    int first = id[(int)from[0]], second = id[(int)to[0]];
    int a, b;
    scanf("%d%d", &a, &b);
    if (first >= 2)
      a = len[first] - a;
    else
      --a;
    if (second >= 2)
      b = len[second] - b;
    else
      --b;
    link[first][a] = make_pair(second, b);
    link[second][b] = make_pair(first, a);
    if (((first - second) & 3) == 2) has[first & 1] = 1;
  }
  if (has[0] && has[1]) printf("No solution\n"), exit(0);
  for (int i = (0), _end_ = (4); i != _end_; ++i)
    for (int j = (0), _end_ = (len[i]); j != _end_; ++j)
      ++cnt[i][(link[i][j].first - i) & 3];
  static pair<int, int> all[max0 + 5];
  for (int i = (0), _end_ = (4); i != _end_; ++i)
    for (int j = (0), _end_ = (len[i]); j != _end_; ++j)
      if (!vis[i][j]) {
        int u = i, v = j;
        int tot = 0;
        do {
          vis[u][v] = 1;
          all[tot++] = make_pair(u, v);
          pair<int, int> tmp = link[u][v];
          vis[tmp.first][tmp.second] = 1;
          all[tot++] = make_pair(tmp.first, tmp.second);
          u = (tmp.first + 2) & 3, v = len[u] - tmp.second - 1;
        } while (u != i || v != j);
        int oril = tot;
        for (int i = (0), _end_ = (tot); i != _end_; ++i) all[tot++] = all[i];
        all[tot++] = make_pair(oo, 0);
        for (int i = tot - 1; i >= 0; --i) all[tot++] = all[i];
        all[tot++] = make_pair(oo, 0);
        const int &l = tot;
        int i = 0, j = 1, k = 0;
        while (i < l && j < l && k < l) {
          int t = (all[(i + k) >= l ? i + k - l : i + k].first) -
                  (all[(j + k) >= l ? j + k - l : j + k].first);
          if (!t)
            ++k;
          else {
            if (t > 0)
              i = max(j + 1, i + k + 1);
            else
              j = max(i + 1, j + k + 1);
            k = 0;
          }
        }
        int t = i < j ? i : j;
        long long t0 = 0, t1 = 0;
        for (int i = (0), _end_ = (oril); i != _end_; ++i) {
          yyt[pig].second.push_back(all[t]);
          ((t0 *= lucky) += all[t].first) %= Mod0;
          ((t1 *= lucky) += all[t].first) %= Mod1;
          if (++t >= tot) t -= tot;
        }
        yyt[pig].first = make_pair(t0, t1);
        ++pig;
      }
  memset(vis, 0, sizeof vis);
  for (int i = (0), _end_ = (4); i != _end_; ++i)
    for (int j = (0), _end_ = (len[i]); j != _end_; ++j)
      if (!vis[i][j]) {
        int u = i, v = j;
        int tot = 0;
        do {
          vis[u][v] = 1;
          all[tot++] = make_pair(u, v);
          static pair<int, int> tmp;
          if (v < cnt[u][3])
            tmp.first = (u - 1) & 3, tmp.second = len[tmp.first] - v - 1;
          else if (v < cnt[u][3] + cnt[u][2]) {
            tmp.first = (u - 2) & 3;
            tmp.second =
                len[tmp.first] - (v - cnt[u][3] + cnt[tmp.first][1]) - 1;
          } else
            tmp.first = (u + 1) & 3, tmp.second = len[u] - v - 1;
          vis[tmp.first][tmp.second] = 1;
          all[tot++] = make_pair(tmp.first, tmp.second);
          u = (tmp.first + 2) & 3, v = len[u] - tmp.second - 1;
        } while (u != i || v != j);
        int oril = tot;
        for (int i = (0), _end_ = (tot); i != _end_; ++i) all[tot++] = all[i];
        all[tot++] = make_pair(oo, 0);
        for (int i = tot - 1; i >= 0; --i) all[tot++] = all[i];
        all[tot++] = make_pair(oo, 0);
        const int &l = tot;
        int i = 0, j = 1, k = 0;
        while (i < l && j < l && k < l) {
          int t = (all[(i + k) >= l ? i + k - l : i + k].first) -
                  (all[(j + k) >= l ? j + k - l : j + k].first);
          if (!t)
            ++k;
          else {
            if (t > 0)
              i = max(j + 1, i + k + 1);
            else
              j = max(i + 1, j + k + 1);
            k = 0;
          }
        }
        int t = i < j ? i : j;
        long long t0 = 0, t1 = 0;
        for (int i = (0), _end_ = (oril); i != _end_; ++i) {
          lyc[orz].second.push_back(all[t]);
          ((t0 *= lucky) += all[t].first) %= Mod0;
          ((t1 *= lucky) += all[t].first) %= Mod1;
          if (++t >= tot) t -= tot;
        }
        lyc[orz].first = make_pair(t0, t1);
        ++orz;
      }
  if (orz != pig) printf("No solution\n"), exit(0);
  for (int i = (0), _end_ = (pig); i != _end_; ++i) pos0[i] = pos1[i] = i;
  sort(pos0, pos0 + pig, cmp0);
  sort(pos1, pos1 + orz, cmp1);
  for (int i = (0), _end_ = (pig); i != _end_; ++i) {
    if (yyt[pos0[i]].first != lyc[pos1[i]].first ||
        (int((yyt[pos0[i]].second).size())) !=
            (int((lyc[pos1[i]].second).size())))
      printf("No solution\n"), exit(0);
    for (int j = (0), _end_ = ((int((yyt[pos0[i]].second).size()))); j != _end_;
         ++j) {
      int u = yyt[pos0[i]].second[j].first, v = yyt[pos0[i]].second[j].second;
      int u0 = lyc[pos1[i]].second[j].first, v0 = lyc[pos1[i]].second[j].second;
      ans[u0 & 1][u0 >= 2 ? len[u0] - v0 - 1 : v0] =
          u >= 2 ? len[u] - v - 1 : v;
    }
  }
  for (int i = (0), _end_ = (2); i != _end_; ++i) {
    for (int j = (0), _end_ = (len[i]); j != _end_; ++j)
      printf("%d ", ans[i][j] + 1);
    printf("\n");
  }
  return 0;
}