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 long long mod = 1000000007;
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= mod;
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
const int N = 401000;
string s1, s2;
vector<int> p1, p2, e[N];
char d0[10], d1[10];
int n, m, x0, x1, rt;
int vis[N], rp[N], po[N];
int minP(string &s) {
  int l = s.length();
  int i = 0, j = 1, k = 0;
  while (i < l && j < l && k < l) {
    if (s[(i + k) % l] == s[(j + k) % l])
      k++;
    else {
      if (s[(i + k) % l] > s[(j + k) % l])
        i += k + 1;
      else
        j += k + 1;
      if (i == j) j++;
      k = 0;
    }
  }
  return min(i, j);
}
int grid(int x, char y) {
  if (y == 'L')
    return x - 1;
  else if (y == 'R')
    return x + n - 1;
  else if (y == 'T')
    return x + n + n - 1;
  else
    return x + n + n + m - 1;
}
char edge(int x) {
  if (x < n)
    return 'L';
  else if (x < n + n)
    return 'R';
  else if (x < n + n + m)
    return 'T';
  else
    return 'B';
}
vector<string> vs;
vector<vector<int> > pp;
bool cmp(int a, int b) { return vs[a] < vs[b]; }
void process(string &s, vector<int> &vp) {
  memset(vis, 0, sizeof(vis));
  vs.clear();
  pp.clear();
  for (int i = 0; i < 2 * (n + m); i++)
    if (!vis[i]) {
      string cs;
      vector<int> cp;
      int p = i, q = e[i][0];
      cp.push_back(p);
      cp.push_back(q);
      while (1) {
        int r = 0;
        r = e[q][p == e[q][0]];
        if (r == i) break;
        cp.push_back(r);
        p = q;
        q = r;
      }
      for (int j = 0; j < ((int)(cp).size()); j++)
        vis[cp[j]] = 1, cs.push_back(edge(cp[j]));
      int p1 = minP(cs);
      string ps1, ps2;
      for (int j = 0; j < ((int)(cs).size()); j++)
        ps1.push_back(cs[(p1 + j) % ((int)(cs).size())]);
      reverse((cs).begin(), (cs).end());
      int p2 = minP(cs);
      for (int j = 0; j < ((int)(cs).size()); j++)
        ps2.push_back(cs[(p2 + j) % ((int)(cs).size())]);
      if (ps1 < ps2) {
        vs.push_back(ps1);
        vector<int> sp;
        for (int j = 0; j < ((int)(ps1).size()); j++)
          sp.push_back(cp[(p1 + j) % ((int)(ps1).size())]);
        pp.push_back(sp);
      } else {
        vs.push_back(ps2);
        reverse((cp).begin(), (cp).end());
        vector<int> sp;
        for (int j = 0; j < ((int)(ps2).size()); j++)
          sp.push_back(cp[(p2 + j) % ((int)(ps2).size())]);
        pp.push_back(sp);
      }
    }
  for (int j = 0; j < ((int)(vs).size()); j++) po[j] = j;
  sort(po, po + ((int)(vs).size()), cmp);
  for (int j = 0; j < ((int)(vs).size()); j++) {
    for (int i = 0; i < ((int)(vs[po[j]]).size()); i++)
      s.push_back(vs[po[j]][i]), vp.push_back(pp[po[j]][i]);
    s.push_back('#');
  }
}
void add(int x, char s, int y, char t) {
  int u = grid(x, s), v = grid(y, t);
  e[u].push_back(v);
  e[v].push_back(u);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i < n + 1; i++) add(i, 'L', i, 'R');
  for (int i = 1; i < m + 1; i++) add(i, 'T', i, 'B');
  for (int i = 0; i < n + m; i++) {
    scanf("%s%s%d%d", d0, d1, &x0, &x1);
    add(x0, d0[0], x1, d1[0]);
    if ((d0[0] == 'R' && d1[0] == 'T') || (d1[0] == 'R' && d0[0] == 'T')) rt++;
  }
  process(s1, p1);
  for (int i = 0; i < 2 * (n + m); i++) e[i].clear();
  for (int i = 1; i < n + 1; i++) add(i, 'L', i, 'R');
  for (int i = 1; i < m + 1; i++) add(i, 'T', i, 'B');
  if (n < m) {
    for (int i = 0; i < n - rt; i++)
      add(i + 1, 'L', i + 1, 'T'), add(m - i, 'B', n - i, 'R');
    for (int i = 0; i < rt; i++)
      add(n - i, 'L', i + 1, 'B'), add(m - i, 'T', i + 1, 'R');
    for (int i = 0; i < m - n; i++) add(n - rt + i + 1, 'T', rt + 1 + i, 'B');
  } else {
    for (int i = 0; i < m - rt; i++)
      add(i + 1, 'L', i + 1, 'T'), add(m - i, 'B', n - i, 'R');
    for (int i = 0; i < rt; i++)
      add(n - i, 'L', i + 1, 'B'), add(m - i, 'T', i + 1, 'R');
    for (int i = 0; i < n - m; i++) add(m - rt + i + 1, 'L', rt + 1 + i, 'R');
  }
  process(s2, p2);
  if (s1 != s2)
    puts("No solution");
  else {
    for (int j = 0; j < ((int)(p2).size()); j++) rp[p2[j]] = p1[j];
    for (int i = 0; i < n; i++) printf("%d ", rp[i] + 1);
    puts("");
    for (int i = n + n; i < n + n + m; i++) printf("%d ", rp[i] - n - n + 1);
    puts("");
  }
}