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;
namespace IO {
const int sz = 1 << 15;
char inbuf[sz], outbuf[sz];
char *pinbuf = inbuf + sz;
char *poutbuf = outbuf;
inline char _getchar() {
  if (pinbuf == inbuf + sz) fread(inbuf, 1, sz, stdin), pinbuf = inbuf;
  return *(pinbuf++);
}
inline void _putchar(char x) {
  if (poutbuf == outbuf + sz) fwrite(outbuf, 1, sz, stdout), poutbuf = outbuf;
  *(poutbuf++) = x;
}
inline void flush() {
  if (poutbuf != outbuf)
    fwrite(outbuf, 1, poutbuf - outbuf, stdout), poutbuf = outbuf;
}
}  // namespace IO
inline int read() {
  int v = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    v = v * 10 + c - '0';
    c = getchar();
  }
  return v * f;
}
const int Maxn = 400005;
const int mod1 = 1e9 + 9;
const int mod2 = 993244853;
const int bas = 1145141;
int n, m;
int C0, C1, C2, C3, C4, C5;
int p[Maxn], rp[Maxn], vis[Maxn], tp[Maxn], trp[Maxn];
int ans0[Maxn], ans1[Maxn];
vector<pair<long long, pair<vector<int>, vector<pair<int, int> > > > > V1, V2;
int op[Maxn];
int id(int x, int y) {
  if (x == 0) return y;
  if (x == 1) return y + n;
  if (x == 2) return y + n + m;
  if (x == 3) return y + n + m + n;
}
pair<int, int> rid(int x) {
  if (x < n) return make_pair(0, x);
  if (x < n + m) return make_pair(1, x - n);
  if (x < n + m + n) return make_pair(2, x - n - m);
  return make_pair(3, x - n - m - n);
}
vector<int> cyc;
vector<pair<int, int> > Od;
void dfs1(int x) {
  if (vis[x]) return;
  vis[x] = 1;
  int nx = p[x];
  cyc.push_back(tp[x]);
  Od.push_back(make_pair(x, nx));
  vis[nx] = 1;
  dfs1(op[nx]);
}
void dfs2(int x) {
  if (vis[x]) return;
  vis[x] = 1;
  int nx = rp[x];
  cyc.push_back(trp[x]);
  Od.push_back(make_pair(x, nx));
  vis[nx] = 1;
  dfs2(op[nx]);
}
int pw1[Maxn], pw2[Maxn];
long long M(vector<int> &X, vector<pair<int, int> > &Y) {
  int H1 = 0, H2 = 0;
  for (int i = 0; i < X.size(); i++) {
    H1 = (1ll * H1 * bas + X[i]) % mod1;
    H2 = (1ll * H2 * bas + X[i]) % mod2;
  }
  int N = X.size();
  long long Mn = 3e18;
  int pos, r = 0;
  for (int i = 0; i < X.size(); i++) {
    long long cur = 1ll * H1 * mod1 + H2;
    if (cur < Mn) {
      Mn = cur;
      r = 0;
      pos = i;
    }
    H1 -= 1ll * pw1[N - 1] * X[i] % mod1;
    if (H1 < 0) H1 += mod1;
    H2 -= 1ll * pw2[N - 1] * X[i] % mod2;
    if (H2 < 0) H2 += mod2;
    H1 = (1ll * H1 * bas + X[i]) % mod1;
    H2 = (1ll * H2 * bas + X[i]) % mod2;
  }
  H1 = 0;
  H2 = 0;
  for (int i = X.size() - 1; i >= 0; i--) {
    H1 = (1ll * H1 * bas + X[i]) % mod1;
    H2 = (1ll * H2 * bas + X[i]) % mod2;
  }
  for (int i = X.size() - 1; i >= 0; i--) {
    long long cur = 1ll * H1 * mod1 + H2;
    if (cur < Mn) {
      Mn = cur;
      r = 1;
      pos = i;
    }
    H1 -= 1ll * pw1[N - 1] * X[i] % mod1;
    if (H1 < 0) H1 += mod1;
    H2 -= 1ll * pw2[N - 1] * X[i] % mod2;
    if (H2 < 0) H2 += mod2;
    H1 = (1ll * H1 * bas + X[i]) % mod1;
    H2 = (1ll * H2 * bas + X[i]) % mod2;
  }
  vector<int> tmp;
  vector<pair<int, int> > tmp2;
  if (!r) {
    for (int i = pos; i < X.size(); i++)
      tmp.push_back(X[i]), tmp2.push_back(Y[i]);
    for (int i = 0; i < pos; i++) tmp.push_back(X[i]), tmp2.push_back(Y[i]);
  } else {
    for (int i = pos; i >= 0; i--) tmp.push_back(X[i]), tmp2.push_back(Y[i]);
    for (int i = X.size() - 1; i > pos; i--)
      tmp.push_back(X[i]), tmp2.push_back(Y[i]);
  }
  X = tmp;
  Y = tmp2;
  return Mn;
}
void Add(int x, int y) {
  pair<int, int> tx = rid(x), ty = rid(y);
  assert(tx.first == ty.first);
  if (tx.first == 0 || tx.first == 2) {
    ans0[ty.second] = tx.second;
  } else {
    ans1[ty.second] = tx.second;
  }
}
int main() {
  pw1[0] = 1;
  pw2[0] = 1;
  for (int i = 1; i < Maxn; i++) {
    pw1[i] = 1ll * pw1[i - 1] * bas % mod1;
    pw2[i] = 1ll * pw2[i - 1] * bas % mod2;
  }
  scanf("%d %d\n", &n, &m);
  for (int i = 0; i < n + m; i++) {
    char a, b;
    a = getchar();
    while (a < 'A' || a > 'Z') a = getchar();
    b = getchar();
    while (b < 'A' || b > 'Z') b = getchar();
    int c, d;
    scanf("%d %d", &c, &d);
    c--;
    d--;
    int id1, id2;
    int w1, w2;
    if (a == 'L')
      id1 = c, w1 = 0;
    else if (a == 'T')
      id1 = n + c, w1 = 1;
    else if (a == 'R')
      id1 = n + m + c, w1 = 2;
    else
      id1 = n + m + n + c, w1 = 3;
    if (b == 'L')
      id2 = d, w2 = 0;
    else if (b == 'T')
      id2 = n + d, w2 = 1;
    else if (b == 'R')
      id2 = n + m + d, w2 = 2;
    else
      id2 = n + m + n + d, w2 = 3;
    p[id1] = id2;
    p[id2] = id1;
    if (w1 > w2) swap(w1, w2);
    if (w1 == 0 && w2 == 1)
      C0++, tp[id1] = tp[id2] = 0;
    else if (w1 == 1 && w2 == 2)
      C1++, tp[id1] = tp[id2] = 1;
    else if (w1 == 2 && w2 == 3)
      C2++, tp[id1] = tp[id2] = 2;
    else if (w1 == 0 && w2 == 3)
      C3++, tp[id1] = tp[id2] = 3;
    else if (w1 == 0 && w2 == 2)
      C4++, tp[id1] = tp[id2] = 4;
    else
      C5++, tp[id1] = tp[id2] = 5;
  }
  for (int i = 0; i < n + m; i++) {
    op[i] = i + n + m;
    op[i + n + m] = i;
  }
  if (C4 && C5) {
    printf("No solution\n");
    return 0;
  }
  if (C0 != C2 || C1 != C3) {
    printf("No solution\n");
    return 0;
  }
  for (int i = 0; i < C0; i++) {
    rp[id(0, i)] = id(1, i);
    rp[id(1, i)] = id(0, i);
    trp[id(0, i)] = trp[id(1, i)] = 0;
    rp[id(2, n - i - 1)] = id(3, m - i - 1);
    rp[id(3, m - i - 1)] = id(2, n - i - 1);
    trp[id(2, n - i - 1)] = trp[id(3, m - i - 1)] = 2;
  }
  for (int i = 0; i < C1; i++) {
    rp[id(1, m - i - 1)] = id(2, i);
    rp[id(2, i)] = id(1, m - i - 1);
    trp[id(1, m - i - 1)] = trp[id(2, i)] = 1;
    rp[id(3, i)] = id(0, n - i - 1);
    rp[id(0, n - i - 1)] = id(3, i);
    trp[id(3, i)] = trp[id(0, n - i - 1)] = 3;
  }
  if (C0 + C1 < m) {
    for (int i = C0; i < m - C1; i++) {
      rp[id(1, i)] = id(3, i - C0 + C1);
      rp[id(3, i - C0 + C1)] = id(1, i);
      trp[id(1, i)] = trp[id(3, i - C0 + C1)] = 5;
    }
  }
  if (C0 + C1 < n) {
    for (int i = C0; i < n - C1; i++) {
      rp[id(0, i)] = id(2, i - C0 + C1);
      rp[id(2, i - C0 + C1)] = id(0, i);
      trp[id(0, i)] = trp[id(2, i - C0 + C1)] = 4;
    }
  }
  memset(vis, 0, sizeof(vis));
  for (int i = 0; i < n + m + n + m; i++) {
    if (!vis[i]) {
      cyc.clear();
      Od.clear();
      dfs1(i);
      long long H = M(cyc, Od);
      V1.push_back(make_pair(H, make_pair(cyc, Od)));
    }
  }
  memset(vis, 0, sizeof(vis));
  for (int i = 0; i < n + m + n + m; i++) {
    if (!vis[i]) {
      cyc.clear();
      Od.clear();
      dfs2(i);
      long long H = M(cyc, Od);
      V2.push_back(make_pair(H, make_pair(cyc, Od)));
    }
  }
  sort(V1.begin(), V1.end());
  sort(V2.begin(), V2.end());
  if (V1.size() != V2.size()) {
    printf("No solution\n");
    return 0;
  }
  for (int i = 0; i < n; i++) ans0[i] = -1;
  for (int i = 0; i < m; i++) ans1[i] = -1;
  for (int i = 0; i < V1.size(); i++) {
    if (V1[i].first != V2[i].first) {
      printf("No solution\n");
      return 0;
    }
    vector<pair<int, int> > P1 = V1[i].second.second, P2 = V2[i].second.second;
    for (int j = 0; j < P1.size(); j++) {
      if (rid(P1[j].first).first != rid(P2[j].first).first) {
        swap(P1[j].first, P1[j].second);
      }
      Add(P1[j].first, P2[j].first);
      Add(P1[j].second, P2[j].second);
    }
  }
  for (int i = 0; i < n; i++) {
    printf("%d ", ans0[i] + 1);
  }
  printf("\n");
  for (int i = 0; i < m; i++) {
    printf("%d ", ans1[i] + 1);
  }
  printf("\n");
  return 0;
}