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;
int rn, cn, vn;
int link[400500];
vector<vector<int> > eights, others;
bool vis[400500];
int diag1[400500], diag2[400500];
int rans[400500], cans[400500];
bool used[400500];
char tmp[400500 * 2];
inline int vid(char s, int x) {
  int b;
  if (s == 'L')
    b = 0;
  else if (s == 'T')
    b = rn;
  else if (s == 'R')
    b = rn + cn;
  else if (s == 'B')
    b = rn + rn + cn;
  return b + x - 1;
}
inline char getstr(int v) {
  if (v < rn)
    return 'L';
  else if (v < rn + cn)
    return 'T';
  else if (v < rn + rn + cn)
    return 'R';
  else
    return 'B';
}
inline int getpos(int v) {
  if (v < rn)
    return v + 1;
  else if (v < rn + cn)
    return v - rn + 1;
  else if (v < rn + rn + cn)
    return v - rn - cn + 1;
  else
    return v - rn - rn - cn + 1;
}
inline int ctp(int v) {
  if (v < rn + cn)
    return v + rn + cn;
  else
    return v - rn - cn;
}
void dfs(int v, vector<int> &cyc) {
  vis[v] = 1;
  cyc.push_back(v);
  int u = link[v];
  int z = ctp(v);
  if (!vis[u]) dfs(u, cyc);
  if (!vis[z]) dfs(z, cyc);
}
void dump(const vector<int> &cyc, char *str) {
  for (int i = 0; i < cyc.size(); i++) str[i] = getstr(cyc[i]);
  str[cyc.size()] = '\0';
}
int is_eight(const vector<int> &cyc) {
  if (cyc.size() != 8) return 0;
  char rep[10];
  dump(cyc, rep);
  if (!strcmp(rep, "LTBLRBTR")) return 1;
  if (!strcmp(rep, "LBTLRTBR")) return 2;
  return 0;
}
void gao_eight() {
  for (int e = 0; e < eights.size(); e++) {
    const vector<int> &cyc = eights[e];
    int type = is_eight(cyc);
    if (type == 1) {
      rans[e] = getpos(cyc[0]);
      cans[e] = getpos(cyc[1]);
      rans[rn - e - 1] = getpos(cyc[3]);
      cans[cn - e - 1] = getpos(cyc[5]);
    } else {
      rans[rn - e - 1] = getpos(cyc[0]);
      cans[e] = getpos(cyc[1]);
      rans[e] = getpos(cyc[3]);
      cans[cn - e - 1] = getpos(cyc[5]);
    }
    used[vid('L', e + 1)] = 1;
    used[vid('L', rn - e)] = 1;
    used[vid('R', e + 1)] = 1;
    used[vid('R', rn - e)] = 1;
    used[vid('T', e + 1)] = 1;
    used[vid('T', cn - e)] = 1;
    used[vid('B', e + 1)] = 1;
    used[vid('B', cn - e)] = 1;
  }
}
inline int gcd(int a, int b) {
  while (b) {
    int t = b;
    b = a % b;
    a = t;
  }
  return a;
}
void gen_diag() {
  vector<int> a1, a2;
  for (int i = rn - 1; i >= 0; i--)
    if (!used[i]) a1.push_back(i);
  for (int i = 0; i < cn; i++)
    if (!used[rn + i]) a1.push_back(rn + i);
  for (int i = 0; i < rn; i++)
    if (!used[rn + cn + i]) a1.push_back(rn + cn + i);
  for (int i = cn - 1; i >= 0; i--)
    if (!used[rn + rn + cn + i]) a1.push_back(rn + rn + cn + i);
  for (int i = 0; i < rn; i++)
    if (!used[i]) a2.push_back(i);
  for (int i = 0; i < cn; i++)
    if (!used[rn + rn + cn + i]) a2.push_back(rn + rn + cn + i);
  for (int i = rn - 1; i >= 0; i--)
    if (!used[rn + cn + i]) a2.push_back(rn + cn + i);
  for (int i = cn - 1; i >= 0; i--)
    if (!used[rn + i]) a2.push_back(rn + i);
  for (int i = 0; i < a1.size(); i++) diag1[a1[i]] = a1[a1.size() - i - 1];
  for (int i = 0; i < a2.size(); i++) diag2[a2[i]] = a2[a2.size() - i - 1];
}
void dfs_diag(int v, int *diag, vector<int> &arr) {
  vis[v] = 1;
  arr.push_back(v);
  int u = diag[v];
  int z = ctp(v);
  if (!vis[u]) dfs_diag(u, diag, arr);
  if (!vis[z]) dfs_diag(z, diag, arr);
}
int lex_smallest_head(char s[], int n) {
  for (int i = 0; i < n; i++) s[i + n] = s[i];
  int i = 0, j = 1, k = 0;
  while (j < n && k < n) {
    if (s[i + k] == s[j + k])
      k++;
    else {
      if (s[i + k] < s[j + k])
        j += k + 1;
      else
        i += k + 1;
      k = 0;
    }
    if (i == j) j++;
  }
  return i;
}
long long hashval(char *s, int len) {
  const int pr = 3333331;
  long long h = 0;
  for (int i = 0; i < len; i++) {
    int x;
    if (s[i] == 'L')
      x = 1;
    else if (s[i] == 'T')
      x = 2;
    else if (s[i] == 'R')
      x = 3;
    else
      x = 4;
    h = h * pr + x;
  }
  return h;
}
long long hashval(const vector<int> &arr) {
  char s[arr.size() + 1];
  dump(arr, s);
  return hashval(s, arr.size());
}
bool try_diag(int *diag) {
  for (int i = 0; i < vn; i++) vis[i] = 0;
  vector<pair<int, vector<int> > > diags;
  for (int i = 0; i < vn; i++) {
    vector<int> arr;
    if (vis[i] || used[i]) continue;
    dfs_diag(i, diag, arr);
    int tl = arr.size();
    dump(arr, tmp);
    int si = lex_smallest_head(tmp, tl);
    vector<int> aaa = arr;
    for (int i = 0; i < tl; i++)
      arr[i] = aaa[si + i < tl ? si + i : si + i - tl];
    diags.push_back(make_pair(hashval(arr), arr));
  }
  vector<pair<int, vector<int> > > origs;
  for (int o = 0; o < others.size(); o++) {
    vector<int> &arr = others[o];
    int tl = arr.size();
    dump(arr, tmp);
    int si = lex_smallest_head(tmp, tl);
    vector<int> aaa = arr;
    for (int i = 0; i < tl; i++)
      arr[i] = aaa[si + i < tl ? si + i : si + i - tl];
    origs.push_back(make_pair(hashval(arr), arr));
  }
  sort(diags.begin(), diags.end());
  sort(origs.begin(), origs.end());
  if (diags.size() != origs.size()) return 0;
  for (int i = 0; i < diags.size(); i++) {
    if (diags[i].first != origs[i].first) return 0;
    if (diags[i].second.size() != origs[i].second.size()) return 0;
    for (int j = 0; j < diags[i].second.size(); j++) {
      int v1 = origs[i].second[j];
      int v2 = diags[i].second[j];
      if (getstr(v1) != getstr(v2)) return 0;
      char c = getstr(v1);
      if (c == 'L' || c == 'R')
        rans[getpos(v2) - 1] = getpos(v1);
      else
        cans[getpos(v2) - 1] = getpos(v1);
    }
  }
  return 1;
}
bool gao_other() {
  gen_diag();
  if (try_diag(diag1) || try_diag(diag2)) return 1;
  return 0;
}
bool solve() {
  vn = (rn + cn) * 2;
  for (int i = 0; i < vn; i++) {
    if (vis[i]) continue;
    vector<int> cyc;
    dfs(i, cyc);
    if (is_eight(cyc))
      eights.push_back(cyc);
    else
      others.push_back(cyc);
  }
  gao_eight();
  if (!gao_other()) return 0;
  for (int i = 0; i < rn; i++) printf("%d ", rans[i]);
  puts("");
  for (int i = 0; i < cn; i++) printf("%d ", cans[i]);
  puts("");
  return 1;
}
int main(void) {
  scanf("%d %d", &rn, &cn);
  for (int i = 0; i < rn + cn; i++) {
    char s1[3], s2[3];
    int x1, x2;
    scanf("%s %s %d %d", s1, s2, &x1, &x2);
    int v1 = vid(s1[0], x1);
    int v2 = vid(s2[0], x2);
    link[v1] = v2;
    link[v2] = v1;
  }
  if (!solve()) puts("No solution");
  return 0;
}