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>
#pragma GCC optimize("Ofast")
using namespace std;
template <typename T>
void UMAX(T &a, T b) {
  a = (a > b ? a : b);
}
template <typename T>
void UMIN(T &a, T b) {
  a = (a < b ? a : b);
}
long long readint() {
  char c = getchar();
  long long ret = 0ll;
  bool neg = 0;
  while (!(c >= '0' && c <= '9')) {
    if (c == '-') neg = 1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    ret = ret * 10ll + (long long)(c - '0');
    c = getchar();
  }
  return neg ? -ret : ret;
}
void putint(long long v) {
  if (v < 0) {
    putchar('-');
    v = -v;
  }
  if (!v) {
    putchar('0');
    return;
  }
  if (v >= 10ll) putint(v / 10ll);
  putchar('0' + (v % 10ll));
}
char readch() {
  char c = getchar();
  while (!(c != ' ' && c != '\n' && c != '\r')) c = getchar();
  return c;
}
int n, m;
namespace SA {
char s[1600005];
int cnt[1600005], rk[1600005], ls[1600005], vy[1600005], tmp[1600005];
void bsort(int n) {
  int i, T = max(3, n * 2) + 4;
  memset(cnt, 0, sizeof(int) * T);
  for (i = 0; i < n; ++i) ++cnt[vy[i]];
  for (i = 1; i <= n + 3 || i <= 3; ++i) cnt[i] += cnt[i - 1];
  for (i = n - 1; i >= 0; --i) tmp[--cnt[vy[i]]] = i;
  memset(cnt, 0, sizeof(int) * T);
  for (i = 0; i < n; ++i) ++cnt[rk[tmp[i]]];
  for (i = 1; i <= n + 3 || i <= 3; ++i) cnt[i] += cnt[i - 1];
  for (i = n - 1; i >= 0; --i) ls[--cnt[rk[tmp[i]]]] = tmp[i];
  memset(tmp, 0, sizeof(int) * T);
}
void getsa(int n) {
  int i, j, cv, T = max(3, n * 2) + 4;
  memset(rk, 0, sizeof(int) * T);
  memset(vy, 0, sizeof(int) * T);
  for (i = 0; i < n; ++i) {
    rk[i] = s[i] - '0' + 1;
  }
  for (i = 2; i <= n * 2; i <<= 1) {
    for (j = 0; j < n; ++j) {
      vy[j] = rk[(j + (i >> 1)) % n];
    }
    bsort(n);
    cv = 1;
    for (j = 0; j < n; ++j) {
      if (j && (rk[ls[j - 1]] != rk[ls[j]] || vy[ls[j - 1]] != vy[ls[j]])) ++cv;
      tmp[ls[j]] = cv;
    }
    memcpy(rk, tmp, sizeof(int) * T);
  }
}
}  // namespace SA
int minrep(string S) {
  int len = (int)S.size(), i;
  memcpy(SA::s, S.c_str(), sizeof(char) * len);
  SA::getsa(len);
  return SA::ls[0];
}
int inarea(int d) {
  if (d < n) return 0;
  if (d < n + m) return 1;
  if (d < n + m + n) return 2;
  return 3;
}
int opposite(int d) {
  if (d < n) return n + m + (n - 1 - d);
  if (d < n + m) return n + m + n + (m - 1 - (d - n));
  if (d < n + m + n) return n - 1 - (d - n - m);
  return m - 1 - (d - n - m - n) + n;
}
int repid(int d) { return d < n + m ? d : opposite(d); }
pair<string, vector<int> > getrep(string s, vector<int> ds) {
  int d = minrep(s);
  rotate(s.begin(), s.begin() + d, s.end());
  rotate(ds.begin(), ds.begin() + d, ds.end());
  return make_pair(s, ds);
}
struct config {
  int opp[400005];
  vector<vector<int> > getstat() {
    int i;
    vector<vector<int> > R(4, vector<int>(4));
    for (i = 0; i < n + m + n + m; ++i) {
      if (opp[i] < i) {
        ++R[inarea(opp[i])][inarea(i)];
      }
    }
    return R;
  }
  bool buildfromstat(vector<vector<int> > S) {
    int pl[4] = {0, n, n + m, n + m + n},
        pr[4] = {n - 1, n + m - 1, n + m + n - 1, n + m + n + m - 1};
    int i, j, k;
    for (i = 0; i < 4; ++i) {
      int x = i, y = (i + 1) % 4, c = S[min(x, y)][max(x, y)];
      while (c--) {
        int a = pr[x]--, b = pl[y]++;
        opp[a] = b;
        opp[b] = a;
      }
    }
    if (S[0][2] && S[1][3]) return 0;
    for (i = 0; i < 2; ++i) {
      int c = S[i][i + 2];
      while (c--) {
        int a = pl[i]++, b = pr[i + 2]--;
        opp[a] = b;
        opp[b] = a;
      }
    }
    for (i = 0; i < 4; ++i) assert(pl[i] == pr[i] + 1);
    return 1;
  }
  bool vis[400005];
  vector<pair<string, vector<int> > > getcycrep() {
    int i, j, k;
    vector<pair<string, vector<int> > > R;
    memset(vis, 0, sizeof(vis));
    for (i = 0; i < n + m; ++i) {
      if (vis[i]) continue;
      string s;
      vector<int> ds;
      for (j = i;; j = opp[opposite(j)]) {
        if (vis[j]) break;
        vis[j] = vis[opposite(j)] = 1;
        s.push_back('0' + inarea(j));
        ds.push_back(repid(j));
        s.push_back('0' + inarea(opposite(j)));
        ds.push_back(repid(opposite(j)));
      }
      pair<string, vector<int> > cur = getrep(s, ds);
      reverse(s.begin(), s.end());
      reverse(ds.begin(), ds.end());
      UMIN(cur, getrep(s, ds));
      R.push_back(cur);
    }
    sort(R.begin(), R.end());
    return R;
  }
} F, T;
int p2d(char c, int d) {
  if (c == 'L') return d;
  if (c == 'B') return n + d;
  if (c == 'R') return opposite(d);
  return opposite(n + d);
}
void fafa() {
  printf("No solution\n");
  exit(0);
}
int res[400005];
int main() {
  int i, j, k;
  n = readint();
  m = readint();
  for (i = 0; i < n + m; ++i) {
    char a = readch(), b = readch();
    int p = readint() - 1, q = readint() - 1;
    F.opp[p2d(a, p)] = p2d(b, q);
    F.opp[p2d(b, q)] = p2d(a, p);
  }
  if (!T.buildfromstat(F.getstat())) fafa();
  vector<pair<string, vector<int> > > rF = F.getcycrep(), rT = T.getcycrep();
  if (rF.size() != rT.size()) fafa();
  for (i = 0; i < (int)rF.size(); ++i) {
    if (rF[i].first != rT[i].first) fafa();
    for (j = 0; j < (int)rF[i].second.size(); ++j) {
      res[rT[i].second[j]] = rF[i].second[j];
    }
  }
  for (i = 0; i < n; ++i) printf("%d ", res[i] + 1);
  printf("\n");
  for (i = 0; i < m; ++i) printf("%d ", res[i + n] + 1 - n);
  printf("\n");
  return 0;
}