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 MAXN = (int)8e5 + 10;
const int W[4][4] = {{0, 1, 2, 5},
                     {1 + 6, 0, 6, 3},
                     {2 + 6, 6 + 6, 0, 4},
                     {5 + 6, 3 + 6, 4 + 6, 0}};
int n, m, a[MAXN], b[MAXN], cnt[7], ID[300], c[MAXN], d[MAXN];
vector<pair<long long, vector<int> > > La, Lb;
int C(int first, int second) { return first * (n + m) + second; }
int Ty(int first, int second, int k) {
  first /= n + m, second /= n + m;
  if (!k)
    if (first > second) swap(first, second);
  return W[first][second];
}
void fail() { puts("No solution"), exit(0); }
void Build() {
  if (cnt[5] && cnt[6]) fail();
  for (int i = 1; i <= cnt[1]; ++i) b[C(0, i)] = C(1, i), b[C(1, i)] = C(0, i);
  for (int i = 1; i <= cnt[2]; ++i)
    b[C(0, m - i + 1)] = C(2, i), b[C(2, i)] = C(0, m - i + 1);
  for (int i = 1; i <= cnt[3]; ++i)
    b[C(1, n - i + 1)] = C(3, i), b[C(3, i)] = C(1, n - i + 1);
  for (int i = 1; i <= cnt[4]; ++i)
    b[C(2, n - i + 1)] = C(3, m - i + 1), b[C(3, m - i + 1)] = C(2, n - i + 1);
  for (int i = 1; i <= cnt[5]; ++i)
    b[C(0, cnt[1] + i)] = C(3, cnt[3] + i),
                    b[C(3, cnt[3] + i)] = C(0, cnt[1] + i);
  for (int i = 1; i <= cnt[6]; ++i)
    b[C(1, cnt[1] + i)] = C(2, cnt[2] + i),
                    b[C(2, cnt[2] + i)] = C(1, cnt[1] + i);
}
int Getminp(vector<int> &a) {
  int i = 0, j = 1, k = 0, l = ((int)(a).size());
  for (; i < l && j < l && k < l;) {
    if (a[(i + k) % l] == a[(j + k) % l])
      ++k;
    else {
      if (a[(i + k) % l] > a[(j + k) % l])
        i = i + k + 1;
      else
        j = j + k + 1;
      if (i == j) ++j;
      k = 0;
    }
  }
  return min(i, j);
}
vector<int> Work(long long &hash, vector<int> &v) {
  vector<int> a;
  for (int i = 0; i < ((int)(v).size()); i += 2)
    a.push_back(Ty(v[i], v[i + 1], 1));
  int p = Getminp(a);
  rotate(a.begin(), a.begin() + p, a.end());
  p *= 2;
  rotate(v.begin(), v.begin() + p, v.end());
  hash = 0;
  for (int i = 0; i < ((int)(a).size()); ++i)
    hash = hash * 13 + (long long)a[i];
  return a;
}
pair<long long, vector<int> > Get_Hash(vector<int> &v) {
  vector<int> v1 = v, v2 = v, t1, t2;
  long long a1 = 0, a2 = 0;
  t1 = Work(a1, v1);
  reverse(v2.begin(), v2.end());
  t2 = Work(a2, v2);
  if (t1 < t2)
    return make_pair(a1, v1);
  else
    return make_pair(a2, v2);
}
void Calc(int *a, vector<pair<long long, vector<int> > > &La) {
  static bool vis[MAXN];
  memset(vis, 0, sizeof(vis));
  for (int j = 0; j < 4; ++j) {
    int R = 0;
    if (j == 0 || j == 3)
      R = m;
    else
      R = n;
    for (int i = C(j, 1); i <= C(j, R); ++i)
      if (!vis[i]) {
        int first = i;
        vector<int> v;
        for (; !vis[first];) {
          vis[first] = 1;
          v.push_back(first);
          first = a[first];
          vis[first] = 1;
          v.push_back(first);
          first = C((first / (n + m)) ^ 3, first % (n + m));
        }
        La.push_back(Get_Hash(v));
      }
  }
  sort(La.begin(), La.end());
}
int main() {
  ID[(int)'T'] = 0, ID[(int)'L'] = 1, ID[(int)'R'] = 2, ID[(int)'B'] = 3;
  char s1[10], s2[10];
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n + m; ++i) {
    int first, second;
    scanf("%s%s%d%d", s1, s2, &first, &second);
    first = C(ID[(int)s1[0]], first);
    second = C(ID[(int)s2[0]], second);
    ++cnt[Ty(first, second, 0)];
    a[first] = second, a[second] = first;
  }
  Build();
  Calc(a, La);
  Calc(b, Lb);
  if (((int)(La).size()) != ((int)(Lb).size())) fail();
  for (int i = 0; i < ((int)(La).size()); ++i) {
    if (La[i].first != Lb[i].first) fail();
    vector<int> &va = La[i].second, vb = Lb[i].second;
    for (int j = 0; j < ((int)(va).size()); ++j) {
      if (va[j] / (n + m) == 0) c[vb[j] % (n + m)] = va[j] % (n + m);
      if (va[j] / (n + m) == 1) d[vb[j] % (n + m)] = va[j] % (n + m);
    }
  }
  for (int i = 1; i <= n; ++i) printf("%d ", d[i]);
  puts("");
  for (int i = 1; i <= m; ++i) printf("%d ", c[i]);
  puts("");
  fclose(stdin);
  fclose(stdout);
  return 0;
}