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>
void Get(int &T) {
  char C;
  bool F = 0;
  for (; C = getchar(), C < '0' || C > '9';)
    if (C == '-') F = 1;
  for (T = C - '0'; C = getchar(), C >= '0' && C <= '9'; T = T * 10 + C - '0')
    ;
  F && (T = -T);
}
void Get(char &C) {
  for (; C = getchar(), C < 'A' || C > 'Z';)
    ;
}
int ID[305];
void Nosolu() {
  puts("No solution");
  exit(0);
}
struct L {
  int V, Next;
} List[400005];
int ListTop;
int Head[400005];
int Go1[5][100005];
int Go2[5][100005];
int GoStar1[5][100005];
int GoStar2[5][100005];
void AddList(int Len, int V) {
  List[++ListTop] = (L){V, Head[Len]};
  Head[Len] = ListTop;
}
void Add(int U1, int U2, int V1, int V2, int G1[][100005] = Go1,
         int G2[][100005] = Go2) {
  G1[U1][U2] = V1;
  G2[U1][U2] = V2;
  G1[V1][V2] = U1;
  G2[V1][V2] = U2;
}
int N, M;
int K;
int P, Q;
void Init() {
  Get(N);
  Get(M);
  K = std::min(N, M);
  ID['T'] = 1;
  ID['L'] = 2;
  ID['R'] = 3;
  ID['B'] = 4;
  char U1, V1;
  int U2, V2;
  for (int i = 1; i <= N + M; i++) {
    Get(U1);
    Get(V1);
    Get(U2);
    Get(V2);
    if (U1 == 'T' && V1 == 'L') P++;
    if (U1 == 'L' && V1 == 'T') P++;
    if (U1 == 'T' && V1 == 'R') Q++;
    if (U1 == 'R' && V1 == 'T') Q++;
    Add(ID[U1], U2, ID[V1], V2);
  }
  if (P + Q != K) Nosolu();
}
int Visited[5][100005];
bool VisitedStar[5][100005];
int Stack[500005];
int Stack2[500005];
int StackStar[5000005];
int StackStar2[5000005];
int Next[5000005];
int StackTop;
int StackTopStar;
int OrderX[100005];
int OrderY[100005];
int OrderX1[100005];
int OrderY1[100005];
void Match(int X, int Y, int X0, int Y0) {
  if (X != X0) Nosolu();
  if (X == 2 || X == 3) {
    if (OrderX[Y] != 0 && OrderX[Y] != Y0) Nosolu();
    if (OrderX1[Y0] != 0 && OrderX1[Y0] != Y) Nosolu();
    OrderX[Y] = Y0;
    OrderX1[Y0] = Y;
  } else {
    if (OrderY[Y] != 0 && OrderY[Y] != Y0) Nosolu();
    if (OrderY1[Y0] != 0 && OrderY1[Y0] != Y) Nosolu();
    OrderY[Y] = Y0;
    OrderY1[Y0] = Y;
  }
}
void Debug() {
  puts("");
  for (int i = 1; i <= StackTop * 2; i++)
    printf("%d     %d   |   %d\n", Stack[i], StackStar[i], Next[i]);
}
int KMP() {
  for (int i = 1; i <= StackTop; i++) {
    StackStar[i + StackTop] = StackStar[i];
    StackStar2[i + StackTop] = StackStar2[i];
  }
  Next[1] = 0;
  for (int i = 2; i <= StackTop; i++) {
    for (Next[i] = Next[i - 1];; Next[i] = Next[Next[i]]) {
      if (Stack[Next[i] + 1] == Stack[i]) {
        Next[i]++;
        break;
      }
      if (Next[i] == 0) break;
    }
  }
  for (int i = 1, j = 0; i <= StackTop * 2; i++) {
    for (;; j = Next[j]) {
      if (StackStar[i] == Stack[j + 1]) {
        j++;
        if (j == StackTop) return i - j + 1;
        break;
      }
      if (j == 0) {
        break;
      }
    }
  }
  for (int i = 1; i <= StackTop; i++) {
    std::swap(StackStar[i], StackStar[StackTop + StackTop - i + 1]);
    std::swap(StackStar2[i], StackStar2[StackTop + StackTop - i + 1]);
  }
  for (int i = 1, j = 0; i <= StackTop * 2; i++) {
    for (;; j = Next[j]) {
      if (StackStar[i] == Stack[j + 1]) {
        j++;
        if (j == StackTop) return i - j + 1;
        break;
      }
      if (j == 0) {
        break;
      }
    }
  }
  Nosolu();
}
void Work() {
  if (N > M) {
    for (int i = 1; i <= P; i++) Add(1, i, 2, i, GoStar1, GoStar2);
    for (int i = 1; i <= Q; i++) Add(1, K - i + 1, 3, i, GoStar1, GoStar2);
    for (int i = 1; i <= N - K; i++) Add(2, P + i, 3, Q + i, GoStar1, GoStar2);
    for (int i = 1; i <= Q; i++) Add(4, i, 2, N - i + 1, GoStar1, GoStar2);
    for (int i = 1; i <= P; i++)
      Add(4, K - i + 1, 3, N - i + 1, GoStar1, GoStar2);
  } else {
    for (int i = 1; i <= Q; i++) Add(2, K - i + 1, 4, i, GoStar1, GoStar2);
    for (int i = 1; i <= P; i++) Add(2, i, 1, i, GoStar1, GoStar2);
    for (int i = 1; i <= M - K; i++) Add(4, Q + i, 1, P + i, GoStar1, GoStar2);
    for (int i = 1; i <= P; i++)
      Add(3, K - i + 1, 4, M - i + 1, GoStar1, GoStar2);
    for (int i = 1; i <= Q; i++) Add(3, i, 1, M - i + 1, GoStar1, GoStar2);
  }
  int k = 0;
  VisitedStar[1][0] = 1;
  for (int i = 1; i <= M; i++) {
    if (Visited[1][i] == 0) {
      int Now1 = 1, Now2 = i;
      StackTop = 0;
      for (;;) {
        Stack[++StackTop] = Now1;
        Visited[Now1][Now2] = 1;
        int NewNow1 = Go1[Now1][Now2];
        int NewNow2 = Go2[Now1][Now2];
        Now1 = NewNow1;
        Now2 = NewNow2;
        Stack[++StackTop] = Now1;
        Visited[Now1][Now2] = 1;
        Now1 = 5 - Now1;
        if (Now1 == 1 && Now2 == i) break;
      }
      if (StackTop == 8 &&
          ((Stack[1] == 1 && Stack[2] == 2 && Stack[3] == 3 && Stack[4] == 1 &&
            Stack[5] == 4 && Stack[6] == 3 && Stack[7] == 2 && Stack[8] == 4) ||
           (Stack[1] == 1 && Stack[2] == 3 && Stack[3] == 2 && Stack[4] == 1 &&
            Stack[5] == 4 && Stack[6] == 2 && Stack[7] == 3 &&
            Stack[8] == 4))) {
        k++;
        int Now1 = 1, Now2 = i;
        int NowStar1 = 1, NowStar2 = k;
        if (Stack[1] == 1 && Stack[2] == 3 && Stack[3] == 2 && Stack[4] == 1 &&
            Stack[5] == 4 && Stack[6] == 2 && Stack[7] == 3 && Stack[8] == 4)
          NowStar2 = M - k + 1;
        for (;;) {
          Match(Now1, Now2, NowStar1, NowStar2);
          Visited[Now1][Now2] = 2;
          VisitedStar[NowStar1][NowStar2] = 1;
          int NewNow1 = Go1[Now1][Now2];
          int NewNow2 = Go2[Now1][Now2];
          int NewStarNow1 = GoStar1[NowStar1][NowStar2];
          int NewStarNow2 = GoStar2[NowStar1][NowStar2];
          Now1 = NewNow1;
          Now2 = NewNow2;
          NowStar1 = NewStarNow1;
          NowStar2 = NewStarNow2;
          Visited[Now1][Now2] = 2;
          VisitedStar[NowStar1][NowStar2] = 1;
          Match(Now1, Now2, NowStar1, NowStar2);
          Now1 = 5 - Now1;
          NowStar1 = 5 - NowStar1;
          if (Now1 == 1 && Now2 == i) break;
        }
      }
    }
  }
  if (k != std::min(P, Q)) Nosolu();
  for (int i = 1; i <= M; i++)
    if (Visited[1][i] != 2) {
      int Now1 = 1, Now2 = i;
      StackTop = 0;
      for (;;) {
        Stack[++StackTop] = Now1;
        Stack2[StackTop] = Now2;
        Visited[Now1][Now2] = 2;
        int NewNow1 = Go1[Now1][Now2];
        int NewNow2 = Go2[Now1][Now2];
        Now1 = NewNow1;
        Now2 = NewNow2;
        Stack[++StackTop] = Now1;
        Stack2[StackTop] = Now2;
        Visited[Now1][Now2] = 2;
        Now1 = 5 - Now1;
        if (Now1 == 1 && Now2 == i) break;
      }
      for (; VisitedStar[1][k] == 1;) k++;
      int NowStar1 = 1, NowStar2 = k;
      StackTopStar = 0;
      for (;;) {
        StackStar[++StackTopStar] = NowStar1;
        StackStar2[StackTopStar] = NowStar2;
        VisitedStar[NowStar1][NowStar2] = 1;
        int NewNow1 = GoStar1[NowStar1][NowStar2];
        int NewNow2 = GoStar2[NowStar1][NowStar2];
        NowStar1 = NewNow1;
        NowStar2 = NewNow2;
        StackStar[++StackTopStar] = NowStar1;
        StackStar2[StackTopStar] = NowStar2;
        VisitedStar[NowStar1][NowStar2] = 1;
        NowStar1 = 5 - NowStar1;
        if (NowStar1 == 1 && NowStar2 == k) break;
      }
      if (StackTop != StackTopStar) Nosolu();
      int Pos = KMP();
      for (int p = 1, q = Pos; p <= StackTop; p++, q++)
        Match(Stack[p], Stack2[p], StackStar[q], StackStar2[q]);
    }
  k = 1;
  for (int i = 1; i <= N; i++)
    if (Visited[2][i] != 2) {
      int Now1 = 2, Now2 = i;
      StackTop = 0;
      for (;;) {
        Stack[++StackTop] = Now1;
        Stack2[StackTop] = Now2;
        Visited[Now1][Now2] = 2;
        int NewNow1 = Go1[Now1][Now2];
        int NewNow2 = Go2[Now1][Now2];
        Now1 = NewNow1;
        Now2 = NewNow2;
        Stack[++StackTop] = Now1;
        Stack2[StackTop] = Now2;
        Visited[Now1][Now2] = 2;
        Now1 = 5 - Now1;
        if (Now1 == 2 && Now2 == i) break;
      }
      for (; VisitedStar[2][k] == 1;) k++;
      int NowStar1 = 2, NowStar2 = k;
      StackTopStar = 0;
      for (;;) {
        StackStar[++StackTopStar] = NowStar1;
        StackStar2[StackTopStar] = NowStar2;
        VisitedStar[NowStar1][NowStar2] = 1;
        int NewNow1 = GoStar1[NowStar1][NowStar2];
        int NewNow2 = GoStar2[NowStar1][NowStar2];
        NowStar1 = NewNow1;
        NowStar2 = NewNow2;
        StackStar[++StackTopStar] = NowStar1;
        StackStar2[StackTopStar] = NowStar2;
        VisitedStar[NowStar1][NowStar2] = 1;
        NowStar1 = 5 - NowStar1;
        if (NowStar1 == 2 && NowStar2 == k) break;
      }
      if (StackTop != StackTopStar) Nosolu();
      int Pos = KMP();
      for (int p = 1, q = Pos; p <= StackTop; p++, q++)
        Match(Stack[p], Stack2[p], StackStar[q], StackStar2[q]);
    }
  for (int i = 1; i <= N; i++)
    if (OrderX1[i] == 0 || OrderX[i] == 0) Nosolu();
  for (int i = 1; i <= M; i++)
    if (OrderY1[i] == 0 || OrderY[i] == 0) Nosolu();
}
void Output() {
  for (int i = 1; i <= N; i++) printf("%d ", OrderX1[i]);
  puts("");
  for (int i = 1; i <= M; i++) printf("%d ", OrderY1[i]);
  puts("");
}
int main() {
  Init();
  Work();
  Output();
  return 0;
}