#include <bits/stdc++.h>
using namespace std;
const int N = 50050, E = 100100, L = 22, T = 1000100;
int n, e, m = 0, c[N] = {}, t[N][2] = {}, team[N] = {}, ct[T] = {};
vector<int> hate[N], wish[N], member[T];
void init() {
  scanf("%d%d", &n, &e);
  for (int i = 1, u, v; i <= e; ++i) {
    scanf("%d%d", &u, &v);
    hate[u].push_back(v);
    hate[v].push_back(u);
  }
  for (int i = 1, l, x; i <= n; ++i) {
    scanf("%d", &l);
    while (l--) {
      scanf("%d", &x);
      wish[i].push_back(x);
      m = max(m, x);
    }
  }
}
void divide_conference() {
  for (int i = 1; i <= n; ++i) c[i] = 0, t[i][0] = hate[i].size(), t[i][1] = 0;
  queue<int> q;
  bool in[N] = {};
  for (int i = 1; i <= n; ++i) {
    q.push(i);
    in[i] = true;
  }
  while (!q.empty()) {
    int s = q.front();
    q.pop();
    in[s] = false;
    if (t[s][c[s]] > t[s][!c[s]]) {
      for (int i = 0; i < (int)hate[s].size(); ++i) {
        int j = hate[s][i];
        --t[j][c[s]], ++t[j][!c[s]];
        if (t[j][c[j]] > t[j][!c[j]] && !in[j]) {
          q.push(j);
          in[j] = true;
        }
      }
      c[s] = !c[s];
    }
  }
}
void divide_team() {
  bool flag = false;
  while (!flag) {
    flag = true;
    for (int i = 1; i <= m; ++i) ct[i] = rand() % 2;
    for (int i = 1; i <= n; ++i) {
      bool fla = false;
      for (int j = 0; j < (int)wish[i].size(); ++j)
        if (ct[wish[i][j]] == c[i]) {
          team[i] = wish[i][j];
          fla = true;
          break;
        }
      if (!fla) {
        flag = false;
        break;
      }
    }
  }
  for (int i = 1; i <= n; ++i) printf("%d ", team[i]);
  printf("\n");
  for (int i = 1; i <= m; ++i) printf("%d ", ct[i] + 1);
  printf("\n");
}
int main() {
  srand(time(0));
  init();
  divide_conference();
  divide_team();
  return 0;
}
