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 long long MOD = 1e9 + 7;
int n, m, tl = 0, tr = 0, bl = 0, br = 0, tb = 0, lr = 0, r[100010], c[100010];
vector<pair<pair<int, int>, pair<int, int> > > g[400010];
vector<pair<vector<int>, vector<pair<int, int> > > > v[2];
pair<vector<int>, vector<pair<int, int> > > vv, vvv;
bool vis[400010];
int ch(int c, int x) {
  if (c == 'T') return x;
  if (c == 'B') return x + m;
  if (c == 'L') return x + m + m;
  return x + m + m + n;
}
int getType(int c1, int c2) {
  if ((c1 == 'T' && c2 == 'B') || (c1 == 'B' && c2 == 'T')) return 0;
  if ((c1 == 'L' && c2 == 'R') || (c1 == 'R' && c2 == 'L')) return 1;
  if ((c1 == 'T' && c2 == 'L') || (c1 == 'L' && c2 == 'T')) return 2;
  if ((c1 == 'T' && c2 == 'R') || (c1 == 'R' && c2 == 'T')) return 3;
  if ((c1 == 'B' && c2 == 'L') || (c1 == 'L' && c2 == 'B')) return 4;
  return 5;
}
bool ck() { return tl != br || tr != bl; }
void addGrid() {
  int x1, x2;
  for (int i = 1; i <= m; ++i) {
    x1 = ch('T', i);
    x2 = ch('B', i);
    g[x1].push_back(make_pair(make_pair(x2, 6), make_pair(0, i)));
    g[x2].push_back(make_pair(make_pair(x1, 6), make_pair(0, i)));
  }
  for (int i = 1; i <= n; ++i) {
    x1 = ch('L', i);
    x2 = ch('R', i);
    g[x1].push_back(make_pair(make_pair(x2, 7), make_pair(1, i)));
    g[x2].push_back(make_pair(make_pair(x1, 7), make_pair(1, i)));
  }
}
void dfs(int pos, int par) {
  vis[pos] = true;
  bool have = false;
  for (int i = 0; i < g[pos].size(); ++i) {
    if (g[pos][i].first.first == par && !have) {
      have = true;
      continue;
    }
    vv.first.push_back(g[pos][i].first.second);
    vv.second.push_back(g[pos][i].second);
    if (vis[g[pos][i].first.first]) return;
    dfs(g[pos][i].first.first, pos);
    break;
  }
}
int getMin(vector<int> x) {
  int k = 0, i = 0, j = 1;
  while (k < x.size() && i < x.size() && j < x.size()) {
    if (x[(i + k) % x.size()] == x[(j + k) % x.size()])
      ++k;
    else {
      if (x[(i + k) % x.size()] > x[(j + k) % x.size()])
        i += k + 1;
      else
        j += k + 1;
      if (i == j) i++;
      k = 0;
    }
  }
  return min(i, j);
}
void calcCyc(int w) {
  for (int i = 0; i < n + n + m + m + 5; ++i) vis[i] = false;
  for (int i = 1; i <= n + n + m + m; ++i)
    if (!vis[i]) {
      vv.first.clear();
      vv.second.clear();
      dfs(i, 0);
      vvv = vv;
      int mn = getMin(vv.first);
      vector<int> tmp1;
      tmp1.clear();
      for (int j = mn; j < vv.first.size(); ++j) tmp1.push_back(vv.first[j]);
      for (int j = 0; j < mn; ++j) tmp1.push_back(vv.first[j]);
      vv.first = tmp1;
      vector<pair<int, int> > tmp2;
      tmp2.clear();
      for (int j = mn; j < vv.second.size(); ++j) tmp2.push_back(vv.second[j]);
      for (int j = 0; j < mn; ++j) tmp2.push_back(vv.second[j]);
      vv.second = tmp2;
      reverse(vvv.first.begin(), vvv.first.end());
      reverse(vvv.second.begin(), vvv.second.end());
      mn = getMin(vvv.first);
      tmp1.clear();
      for (int j = mn; j < vvv.first.size(); ++j) tmp1.push_back(vvv.first[j]);
      for (int j = 0; j < mn; ++j) tmp1.push_back(vvv.first[j]);
      vvv.first = tmp1;
      tmp2.clear();
      for (int j = mn; j < vvv.second.size(); ++j)
        tmp2.push_back(vvv.second[j]);
      for (int j = 0; j < mn; ++j) tmp2.push_back(vvv.second[j]);
      vvv.second = tmp2;
      v[w].push_back(min(vv, vvv));
    }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  char c1, c2;
  int x1, x2;
  for (int i = 0; i < n + m; ++i) {
    cin >> c1 >> c2 >> x1 >> x2;
    x1 = ch(c1, x1);
    x2 = ch(c2, x2);
    int ty = getType(c1, c2);
    if (ty == 0)
      ++tb;
    else if (ty == 1)
      ++lr;
    else if (ty == 2)
      ++tl;
    else if (ty == 3)
      ++tr;
    else if (ty == 4)
      ++bl;
    else
      ++br;
    g[x1].push_back(make_pair(make_pair(x2, ty), make_pair(0, 0)));
    g[x2].push_back(make_pair(make_pair(x1, ty), make_pair(0, 0)));
  }
  if ((tb > 0 && lr > 0) || ck()) {
    puts("No solution");
    return 0;
  }
  addGrid();
  calcCyc(0);
  sort(v[0].begin(), v[0].end());
  for (int i = 0; i < n + n + m + m + 5; ++i) g[i].clear();
  addGrid();
  for (int i = 1; i <= tl; ++i) {
    x1 = ch('T', i);
    x2 = ch('L', i);
    int ty = getType('T', 'L');
    g[x1].push_back(make_pair(make_pair(x2, ty), make_pair(0, 0)));
    g[x2].push_back(make_pair(make_pair(x1, ty), make_pair(0, 0)));
  }
  for (int i = 1; i <= bl; ++i) {
    x1 = ch('L', n - i + 1);
    x2 = ch('B', i);
    int ty = getType('B', 'L');
    g[x1].push_back(make_pair(make_pair(x2, ty), make_pair(0, 0)));
    g[x2].push_back(make_pair(make_pair(x1, ty), make_pair(0, 0)));
  }
  for (int i = 1; i <= tr; ++i) {
    x1 = ch('T', m - i + 1);
    x2 = ch('R', i);
    int ty = getType('T', 'R');
    g[x1].push_back(make_pair(make_pair(x2, ty), make_pair(0, 0)));
    g[x2].push_back(make_pair(make_pair(x1, ty), make_pair(0, 0)));
  }
  for (int i = 1; i <= br; ++i) {
    x1 = ch('B', m - i + 1);
    x2 = ch('R', n - i + 1);
    int ty = getType('B', 'R');
    g[x1].push_back(make_pair(make_pair(x2, ty), make_pair(0, 0)));
    g[x2].push_back(make_pair(make_pair(x1, ty), make_pair(0, 0)));
  }
  if (tb > 0) {
    for (int i = tl + 1, j = bl + 1; i < m - tr + 1; ++i, ++j) {
      x1 = ch('T', i);
      x2 = ch('B', j);
      int ty = getType('T', 'B');
      g[x1].push_back(make_pair(make_pair(x2, ty), make_pair(0, 0)));
      g[x2].push_back(make_pair(make_pair(x1, ty), make_pair(0, 0)));
    }
  } else {
    for (int i = tl + 1, j = tr + 1; i < n - bl + 1; ++i, ++j) {
      x1 = ch('L', i);
      x2 = ch('R', j);
      int ty = getType('L', 'R');
      g[x1].push_back(make_pair(make_pair(x2, ty), make_pair(0, 0)));
      g[x2].push_back(make_pair(make_pair(x1, ty), make_pair(0, 0)));
    }
  }
  calcCyc(1);
  sort(v[1].begin(), v[1].end());
  bool ok = true;
  if (v[0].size() != v[1].size()) ok = false;
  if (ok)
    for (int i = 0; i < v[0].size(); ++i)
      if (v[0][i].first != v[1][i].first) ok = false;
  if (!ok) {
    puts("No solution");
    return 0;
  }
  for (int i = 0; i < v[0].size(); ++i)
    for (int j = 0; j < v[0][i].first.size(); ++j)
      if (v[0][i].second[j].second > 0) {
        if (v[0][i].second[j].first == 0)
          c[v[1][i].second[j].second] = v[0][i].second[j].second;
        else
          r[v[1][i].second[j].second] = v[0][i].second[j].second;
      }
  for (int i = 1; i <= n; ++i) cout << r[i] << ' ';
  cout << endl;
  for (int i = 1; i <= m; ++i) cout << c[i] << ' ';
  cout << endl;
  return 0;
}