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 H = 257, M = 998244353;
void outno() {
  cout << "No solution";
  exit(0);
}
int n, m;
int cnt[4][4];
vector<pair<int, int> > g[100004][4], f[100004][4];
int L[4], R[4];
bool vis[2][100004][4];
vector<pair<int, int> > v1, v2;
void gotverg(int x, int y) {
  vis[0][x][y] = 1;
  v1.push_back(make_pair(x, y));
  for (auto z : g[x][y])
    if (!vis[0][z.first][z.second]) gotverg(z.first, z.second);
}
void gotverf(int x, int y) {
  vis[1][x][y] = 1;
  v2.push_back(make_pair(x, y));
  for (auto z : f[x][y])
    if (!vis[1][z.first][z.second]) gotverf(z.first, z.second);
}
vector<pair<int, int> > minshow(vector<pair<int, int> > v) {
  vector<pair<int, int> > res;
  int N = v.size(), ans = 0;
  int i = 0, j = 1, k = 0, tmp;
  while (i < N && j < N && k < N) {
    if (v[(i + k) % N].second == v[(j + k) % N].second)
      k++;
    else {
      if (v[(i + k) % N].second > v[(j + k) % N].second)
        i += k + 1;
      else
        j += k + 1;
      if (i == j) j++;
      k = 0;
    }
  }
  tmp = min(i, j);
  for (int i = 0; i < N; i++) res.push_back(v[(tmp + i) % N]);
  return res;
}
int gethash(vector<pair<int, int> > v) {
  int ans = 0;
  for (auto x : v) ans = ((long long)ans * H + x.second + 22) % M;
  return ans;
}
int ans1[100004], ans2[100004];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    g[i][0].push_back(make_pair(i, 2)), g[i][2].push_back(make_pair(i, 0));
  for (int i = 1; i <= m; i++)
    g[i][3].push_back(make_pair(i, 1)), g[i][1].push_back(make_pair(i, 3));
  for (int i = 1; i <= n; i++)
    f[i][0].push_back(make_pair(i, 2)), f[i][2].push_back(make_pair(i, 0));
  for (int i = 1; i <= m; i++)
    f[i][3].push_back(make_pair(i, 1)), f[i][1].push_back(make_pair(i, 3));
  for (int i = 1; i <= n + m; i++) {
    char c1, c2;
    int a, b;
    int i1, i2;
    cin >> c1 >> c2 >> a >> b;
    if (c1 == 'L') i1 = 0;
    if (c1 == 'T') i1 = 1;
    if (c1 == 'R') i1 = 2;
    if (c1 == 'B') i1 = 3;
    if (c2 == 'L') i2 = 0;
    if (c2 == 'T') i2 = 1;
    if (c2 == 'R') i2 = 2;
    if (c2 == 'B') i2 = 3;
    if (i1 > i2) swap(i1, i2), swap(a, b);
    cnt[i1][i2]++;
    g[a][i1].push_back(make_pair(b, i2)), g[b][i2].push_back(make_pair(a, i1));
  }
  if (cnt[0][2] && cnt[1][3]) outno();
  R[0] = R[2] = n + 1, R[1] = R[3] = m + 1;
  for (int i = 0; i < cnt[0][1]; i++)
    ++L[0], ++L[1], f[L[0]][0].push_back(make_pair(L[1], 1)),
        f[L[1]][1].push_back(make_pair(L[0], 0));
  for (int i = 0; i < cnt[1][2]; i++)
    --R[1], ++L[2], f[R[1]][1].push_back(make_pair(L[2], 2)),
        f[L[2]][2].push_back(make_pair(R[1], 1));
  for (int i = 0; i < cnt[2][3]; i++)
    --R[2], --R[3], f[R[2]][2].push_back(make_pair(R[3], 3)),
        f[R[3]][3].push_back(make_pair(R[2], 2));
  for (int i = 0; i < cnt[0][3]; i++)
    --R[0], ++L[3], f[R[0]][0].push_back(make_pair(L[3], 3)),
        f[L[3]][3].push_back(make_pair(R[0], 0));
  for (int i = 0; i < cnt[0][2]; i++)
    ++L[0], ++L[2], f[L[0]][0].push_back(make_pair(L[2], 2)),
        f[L[2]][2].push_back(make_pair(L[0], 0));
  for (int i = 0; i < cnt[1][3]; i++)
    ++L[1], ++L[3], f[L[1]][1].push_back(make_pair(L[3], 3)),
        f[L[3]][3].push_back(make_pair(L[1], 1));
  vector<pair<pair<int, int>, pair<int, int> > > rg, rf;
  for (int i = 0; i < 4; i++)
    for (int j = 1; j <= ((i & 1) ? m : n); j++)
      if (!vis[0][j][i]) {
        v1.clear(), gotverg(j, i);
        vector<pair<int, int> > tmp1 = minshow(v1);
        int hsh1 = gethash(tmp1);
        reverse(v1.begin(), v1.end());
        vector<pair<int, int> > tmp2 = minshow(v1);
        int hsh2 = gethash(tmp2);
        if (hsh1 > hsh2) swap(hsh1, hsh2);
        rg.push_back(make_pair(make_pair(hsh1, hsh2), make_pair(j, i)));
      }
  for (int i = 0; i < 4; i++)
    for (int j = 1; j <= ((i & 1) ? m : n); j++)
      if (!vis[1][j][i]) {
        v2.clear(), gotverf(j, i);
        vector<pair<int, int> > tmp1 = minshow(v2);
        int hsh1 = gethash(tmp1);
        reverse(v2.begin(), v2.end());
        vector<pair<int, int> > tmp2 = minshow(v2);
        int hsh2 = gethash(tmp2);
        if (hsh1 > hsh2) swap(hsh1, hsh2);
        rf.push_back(make_pair(make_pair(hsh1, hsh2), make_pair(j, i)));
      }
  if (rg.size() != rf.size()) outno();
  memset(vis, 0, sizeof(vis));
  sort(rg.begin(), rg.end()), sort(rf.begin(), rf.end());
  for (int i = 0; i < rg.size(); i++) {
    pair<pair<int, int>, pair<int, int> > p1 = rg[i], p2 = rf[i];
    if (p1.first != p2.first) outno();
    v1.clear(), v2.clear();
    int xx = p1.second.first, yy = p1.second.second, XX = p2.second.first,
        YY = p2.second.second;
    gotverg(xx, yy), gotverf(XX, YY);
    v1 = minshow(v1), v2 = minshow(v2);
    int t1 = gethash(v1), t2 = gethash(v2);
    if (t1 != t2) reverse(v2.begin(), v2.end());
    v1 = minshow(v1), v2 = minshow(v2);
    for (int i = 0; i < v1.size(); i++) {
      int x = v1[i].first, y = v1[i].second;
      if (y == 0) ans1[v2[i].first] = x;
      if (y == 1) ans2[v2[i].first] = x;
    }
  }
  for (int i = 1; i <= n; i++) cout << ans1[i] << " ";
  cout << "\n";
  for (int i = 1; i <= m; i++) cout << ans2[i] << " ";
}