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;
set<int> hs[2];
set<int>::iterator it;
struct pp {
  int ip, id, a, b;
};
pp ls[410000];
int cnt_ls;
int n, m, cnt_list[6], po[4][110000], bs[4][110000];
char ss[] = {'L', 'T', 'B', 'R'};
int pos[1256], ps[4][4], cnt, per[2][110000], root, rf;
char ch1, ch2;
bool vis[2][110000], fir, rev;
char chg(char ch) {
  if (ch == 'L') return 'T';
  if (ch == 'T') return 'L';
  if (ch == 'B') return 'R';
  if (ch == 'R') return 'B';
}
bool dfs(int ip, int id, int pre, int pre_id, int &low, int &high) {
  int i, j, s, p, q, ie, ip1, ip2, iq, npre, nlow, nhigh;
  if (fir && ip == rf && id == root) return low <= high;
  fir = true;
  vis[ip][id] = true;
  ls[cnt_ls].ip = ip;
  ls[cnt_ls++].id = id;
  if (ip == 0) {
    ip1 = 0;
    ip2 = bs[0][id];
    if (ip2 == 1 && pre != 0) {
      high = min(high, cnt_list[0] - 1);
      npre = 0;
      ls[cnt_ls - 1].a = 1;
      ls[cnt_ls - 1].b = 0;
      return dfs(1, po[0][id], npre, id, low, high);
    } else if (ip2 == 2 && pre != 1) {
      nlow = n - 1 - high;
      nhigh = n - 1 - low;
      nhigh = min(nhigh, cnt_list[1] - 1);
      low = nlow;
      high = nhigh;
      npre = 1;
      ls[cnt_ls - 1].a = -1;
      ls[cnt_ls - 1].b = n - 1;
      return dfs(1, po[0][id], npre, id, low, high);
    } else if (ip2 == 3)
      return false;
    ip1 = 3;
    ip2 = bs[3][id];
    if (ip2 == 0) return false;
    if (ip2 == 1) {
      nlow = m - 1 - high;
      nhigh = m - 1 - low;
      nlow = max(nlow, m - cnt_list[4]);
      low = nlow;
      high = nhigh;
      npre = 4;
      ls[cnt_ls - 1].a = -1;
      ls[cnt_ls - 1].b = m - 1;
      return dfs(1, po[3][id], npre, id, low, high);
    } else if (ip2 == 2) {
      nlow = low + m - n;
      nhigh = m - n + high;
      nlow = max(nlow, m - cnt_list[5]);
      low = nlow;
      high = nhigh;
      npre = 5;
      ls[cnt_ls - 1].a = 1;
      ls[cnt_ls - 1].b = m - n;
      return dfs(1, po[3][id], npre, id, low, high);
    }
  } else {
    ip1 = 1;
    ip2 = bs[1][id];
    if (ip2 == 0 && pre != 0) {
      high = min(high, cnt_list[0] - 1);
      npre = 0;
      ls[cnt_ls - 1].a = 1;
      ls[cnt_ls - 1].b = 0;
      return dfs(0, po[1][id], npre, id, low, high);
    } else if (ip2 == 2 && (pre != 3 || po[1][id] != pre_id)) {
      nlow = low - cnt_list[0] + cnt_list[1];
      nhigh = high - cnt_list[0] + cnt_list[1];
      nlow = max(nlow, cnt_list[1]);
      nhigh = min(nhigh, m - 1 - cnt_list[5]);
      low = nlow;
      high = nhigh;
      npre = 3;
      ls[cnt_ls - 1].a = 1;
      ls[cnt_ls - 1].b = cnt_list[1] - cnt_list[0];
      return dfs(1, po[1][id], npre, id, low, high);
    } else if (ip2 == 3 && pre != 4) {
      nlow = m - 1 - high;
      nhigh = m - 1 - low;
      nhigh = min(nhigh, cnt_list[4] - 1);
      low = nlow;
      high = nhigh;
      npre = 4;
      ls[cnt_ls - 1].a = -1;
      ls[cnt_ls - 1].b = m - 1;
      return dfs(0, po[1][id], npre, id, low, high);
    }
    ip1 = 2;
    ip2 = bs[2][id];
    if (ip2 == 0) {
      nlow = n - 1 - high;
      nhigh = n - 1 - low;
      nlow = max(nlow, n - cnt_list[1]);
      low = nlow;
      high = nhigh;
      npre = 1;
      ls[cnt_ls - 1].a = -1;
      ls[cnt_ls - 1].b = n - 1;
      return dfs(0, po[2][id], npre, id, low, high);
    } else if (ip2 == 1) {
      nlow = low - cnt_list[1] + cnt_list[0];
      nhigh = high - cnt_list[1] + cnt_list[0];
      nlow = max(nlow, cnt_list[0]);
      nhigh = min(nhigh, m - 1 - cnt_list[4]);
      low = nlow;
      high = nhigh;
      npre = 3;
      ls[cnt_ls - 1].a = 1;
      ls[cnt_ls - 1].b = cnt_list[0] - cnt_list[1];
      return dfs(1, po[2][id], npre, id, low, high);
    } else if (ip2 == 3) {
      nlow = low + n - m;
      nhigh = high + n - m;
      nlow = max(nlow, n - cnt_list[5]);
      low = nlow;
      high = nhigh;
      npre = 5;
      ls[cnt_ls - 1].a = 1;
      ls[cnt_ls - 1].b = n - m;
      return dfs(0, po[2][id], npre, id, low, high);
    }
  }
}
int main() {
  int i, j, s, p, q, id1, id2, ip1, ip2, id, ip, u1, u2, low, high;
  scanf("%d%d", &n, &m);
  rev = false;
  if (n > m) {
    swap(n, m);
    rev = true;
  }
  for (i = 0; i < 4; i++) pos[ss[i]] = i;
  cnt = 0;
  for (i = 0; i < 4; i++)
    for (j = i + 1; j < 4; j++) ps[i][j] = cnt++;
  memset(cnt_list, 0, sizeof(cnt_list));
  for (i = 0; i < n + m; i++) {
    ch1 = getchar();
    while (!(ch1 >= 'A' && ch1 <= 'Z')) ch1 = getchar();
    ch2 = getchar();
    while (!(ch2 >= 'A' && ch2 <= 'Z')) ch2 = getchar();
    scanf("%d%d", &id1, &id2);
    id1--;
    id2--;
    if (rev) {
      ch1 = chg(ch1);
      ch2 = chg(ch2);
    }
    if (pos[ch1] > pos[ch2]) {
      swap(ch1, ch2);
      swap(id1, id2);
    }
    id = ps[pos[ch1]][pos[ch2]];
    po[pos[ch1]][id1] = id2;
    bs[pos[ch1]][id1] = pos[ch2];
    po[pos[ch2]][id2] = id1;
    bs[pos[ch2]][id2] = pos[ch1];
    cnt_list[id]++;
  }
  if (cnt_list[0] != cnt_list[5] || cnt_list[1] != cnt_list[4]) {
    puts("No solution");
    return 0;
  }
  memset(vis, false, sizeof(vis));
  hs[0].clear();
  hs[1].clear();
  for (i = 0; i < n; i++) hs[0].insert(i);
  for (i = 0; i < m; i++) hs[1].insert(i);
  for (i = 0; i < n; i++) {
    if (vis[0][i]) continue;
    root = i;
    rf = 0;
    cnt_ls = 0;
    fir = false;
    low = 0;
    high = n - 1;
    if (!dfs(0, i, -1, -1, low, high)) {
      puts("No solution");
      return 0;
    }
    it = hs[0].lower_bound(low);
    if (it == hs[0].end() || *it > high) {
      puts("No solution");
      return 0;
    }
    low = *it;
    for (j = 0; j < cnt_ls; j++) {
      per[ls[j].ip][low] = ls[j].id + 1;
      it = hs[ls[j].ip].find(low);
      if (it == hs[ls[j].ip].end()) {
        puts("No solution");
        return 0;
      }
      hs[ls[j].ip].erase(low);
      low = ls[j].a * low + ls[j].b;
    }
  }
  for (i = 0; i < m; i++) {
    low = 0;
    high = m - 1;
    if (vis[1][i]) continue;
    rf = 1;
    root = i;
    cnt_ls = 0;
    fir = false;
    if (!dfs(1, i, -1, -1, low, high)) {
      puts("No solution");
      return 0;
    }
    it = hs[1].lower_bound(low);
    if (it == hs[1].end() || *it > high) {
      puts("No solution");
      return 0;
    }
    low = *it;
    for (j = 0; j < cnt_ls; j++) {
      per[ls[j].ip][low] = ls[j].id + 1;
      it = hs[ls[j].ip].find(low);
      if (it == hs[ls[j].ip].end()) {
        puts("No solution");
        return 0;
      }
      hs[ls[j].ip].erase(low);
      low = ls[j].a * low + ls[j].b;
    }
  }
  if (rev) {
    swap(n, m);
    for (i = 0; i < n || i < m; i++) swap(per[0][i], per[1][i]);
  }
  for (i = 0; i < n; i++) printf("%d ", per[0][i]);
  printf("\n");
  for (i = 0; i < m; i++) printf("%d ", per[1][i]);
  printf("\n");
  return 0;
}