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;
template <class T>
inline bool Up(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool Down(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
inline int getus() {
  int tmp, c;
  while (tmp = fgetc(stdin), tmp < '0' || tmp > '9')
    ;
  tmp -= '0';
  while (c = fgetc(stdin), '0' <= c && c <= '9') tmp = tmp * 10 + c - '0';
  return tmp;
}
inline int getint() {
  int tmp, c, flag;
  while (flag = fgetc(stdin), flag != '-' && (flag < '0' || flag > '9'))
    ;
  if (flag == '-')
    tmp = 0;
  else
    tmp = flag - '0';
  while (c = fgetc(stdin), '0' <= c && c <= '9') tmp = tmp * 10 + c - '0';
  return flag == '-' ? -tmp : tmp;
}
int R, C, N, vis[400023], done[400023], ansR[400023], ansC[400023];
int s[400023], d1[400023], d2[400023];
vector<vector<int> > cycles_1, cycles_2;
int lex_smallest_head(string s) {
  int n = s.size(), i = 0, j = 1, k = 0;
  s += s;
  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;
}
inline int encode(char c, int x) {
  if (c == 'L') return x;
  if (c == 'T') return x + R;
  if (c == 'R') return x + N;
  if (c == 'B') return x + N + R;
  assert(0);
  return -1;
}
inline pair<char, int> decode(int x) {
  if (x < R) return pair<char, int>('L', x);
  if (x < N) return pair<char, int>('T', x - R);
  if (x < N + R) return pair<char, int>('R', x - N);
  if (x < N + N) return pair<char, int>('B', x - N - R);
  assert(0);
  return pair<char, int>('_', -1);
}
inline int opposite(int x) {
  if (x < N) return x + N;
  return x - N;
}
inline string getProfile(const vector<int> &cycle) {
  string res(cycle.size(), '\0');
  int size = cycle.size();
  for (int i = (0); i < (size); ++i) res[i] = decode(cycle[i]).first;
  return res;
}
inline int getType(const vector<int> &cycle) {
  if (cycle.size() != 8) return 0;
  string s = getProfile(cycle);
  if (s == "LTBLRBTR") return 1;
  if (s == "LBTLRTBR") return 2;
  return 0;
}
void DFS(int x, int *next, vector<int> &to) {
  if (vis[x]) return;
  vis[x] = true;
  to.push_back(x);
  DFS(next[x], next, to);
  DFS(opposite(x), next, to);
}
void shift(vector<int> &s, int shift) {
  vector<int> tmp(s);
  int size = s.size();
  for (int i = (0); i < (size); ++i) s[i] = tmp[(i + shift) % size];
}
bool match(int *next) {
  vector<vector<int> > S, T;
  for (int i = 0, size = cycles_2.size(); i < size; ++i) {
    vector<int> &c = cycles_2[i];
    string tmp = getProfile(c);
    shift(c, lex_smallest_head(tmp));
    S.push_back(c);
  }
  memcpy(vis, done, sizeof(vis));
  for (int i = (0); i < (N); ++i)
    if (!vis[i]) {
      vector<int> c;
      DFS(i, next, c);
      string tmp = getProfile(c);
      shift(c, lex_smallest_head(tmp));
      T.push_back(c);
    }
  int n = S.size();
  if (n != (int)T.size()) return false;
  if (n == 0) return true;
  int m = S[0].size();
  for (int i = (0); i < (n); ++i)
    if (m != (int)T[i].size()) return false;
  sort(S.begin(), S.end());
  sort(T.begin(), T.end());
  for (int i = (0); i < (n); ++i)
    for (int j = (0); j < (m); ++j) {
      int s = S[i][j], t = T[i][j];
      pair<char, int> ss(decode(s)), tt(decode(t));
      if (ss.first != tt.first) return false;
      if (ss.first == 'L' || ss.first == 'R')
        ansR[tt.second] = ss.second;
      else
        ansC[tt.second] = ss.second;
    }
  return true;
}
int main() {
  memset(vis, 0, sizeof(vis));
  memset(done, 0, sizeof(done));
  scanf("%d %d\n", &R, &C);
  N = R + C;
  for (int i = (0); i < (N); ++i) {
    char c1, c2;
    int x1, x2, p1, p2;
    scanf("%c %c %d %d\n", &c1, &c2, &x1, &x2);
    p1 = encode(c1, --x1);
    p2 = encode(c2, --x2);
    s[p1] = p2;
    s[p2] = p1;
  }
  for (int i = (0); i < (N); ++i)
    if (!vis[i]) {
      vector<int> cycle;
      DFS(i, s, cycle);
      if (getType(cycle))
        cycles_1.push_back(cycle);
      else
        cycles_2.push_back(cycle);
    }
  int cnt = 0;
  for (int size = cycles_1.size(), i = 0; i < size; ++i) {
    const vector<int> &cycle = cycles_1[i];
    int type = getType(cycle), a, b, c, d;
    if (type == 1) {
      ansR[i] = a = decode(cycle[0]).second;
      ansR[R - 1 - i] = b = decode(cycle[3]).second;
      ansC[i] = c = decode(cycle[1]).second;
      ansC[C - 1 - i] = d = decode(cycle[6]).second;
    } else {
      ansR[i] = a = decode(cycle[3]).second;
      ansR[R - 1 - i] = b = decode(cycle[0]).second;
      ansC[i] = c = decode(cycle[2]).second;
      ansC[C - 1 - i] = d = decode(cycle[5]).second;
    }
    done[encode('L', i)] = done[encode('L', R - 1 - i)] = 1;
    done[encode('R', i)] = done[encode('R', R - 1 - i)] = 1;
    done[encode('T', i)] = done[encode('T', C - 1 - i)] = 1;
    done[encode('B', i)] = done[encode('B', C - 1 - i)] = 1;
  }
  vector<int> o(N + N, 0);
  cnt = 0;
  for (int i = (R - 1); i >= (0); --i)
    if (!done[i]) o[cnt++] = i;
  for (int i = (0); i < (C); ++i)
    if (!done[i + R]) o[cnt++] = i + R;
  for (int i = (0); i < (R); ++i)
    if (!done[i + N]) o[cnt++] = i + N;
  for (int i = (C - 1); i >= (0); --i)
    if (!done[i + N + R]) o[cnt++] = i + N + R;
  for (int i = (0); i < (cnt); ++i) d1[o[i]] = o[cnt - 1 - i];
  cnt = 0;
  for (int i = (0); i < (R); ++i)
    if (!done[i]) o[cnt++] = i;
  for (int i = (0); i < (C); ++i)
    if (!done[i + N + R]) o[cnt++] = i + N + R;
  for (int i = (R - 1); i >= (0); --i)
    if (!done[i + N]) o[cnt++] = i + N;
  for (int i = (C - 1); i >= (0); --i)
    if (!done[i + R]) o[cnt++] = i + R;
  for (int i = (0); i < (cnt); ++i) d2[o[i]] = o[cnt - 1 - i];
  if (match(d1) || match(d2)) {
    for (int i = (0); i < (R); ++i)
      printf("%d%c", ansR[i] + 1, (i == R - 1) ? '\n' : ' ');
    for (int i = (0); i < (C); ++i)
      printf("%d%c", ansC[i] + 1, (i == C - 1) ? '\n' : ' ');
  } else
    puts("No solution");
  return 0;
}