#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<int> g[50005];
vector<int> t[50005];
int T;
int col[1000005];
int team[50005];
mt19937 mt(1235577);
int x[100005], y[100005];
int ans[50005];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < (int)(m); ++i) {
    int from, to;
    scanf("%d%d", &from, &to), --from, --to;
    x[i] = from;
    y[i] = to;
    g[from].push_back(to);
    g[to].push_back(from);
  }
  for (int i = 0; i < (int)(n); ++i) {
    int cnt;
    scanf("%d", &cnt);
    for (int j = 0; j < (int)(cnt); ++j) {
      int x;
      scanf("%d", &x), --x;
      T = max(T, x + 1);
      t[i].push_back(x);
    }
  }
  int times = 0;
  while (true) {
    assert(times++ < 100);
    for (int i = 0; i < (int)(T); ++i) {
      col[i] = mt() & 1;
    }
    bool ok = true;
    bool was[2];
    for (int i = 0; i < (int)(n); ++i) {
      was[0] = was[1] = false;
      for (int x : t[i]) {
        was[col[x]] = true;
      }
      if (!was[0] || !was[1]) {
        ok = false;
        break;
      }
    }
    if (ok) {
      break;
    }
  }
  while (true) {
    for (int i = 0; i < (int)(n); ++i) team[i] = mt() & 1;
    int cnt = 0;
    for (int i = 0; i < (int)(m); ++i)
      if (team[x[i]] != team[y[i]]) {
        ++cnt;
      }
    if (2 * cnt < m) {
      continue;
    }
    for (int i = 0; i < (int)(n); ++i) {
      for (int x : t[i])
        if (col[x] == team[i]) {
          ans[i] = x;
          break;
        }
    }
    bool firstTime = true;
    for (int i = 0; i < (int)(n); ++i) {
      if (!firstTime) {
        printf(" ");
      }
      firstTime = false;
      printf("%d", ans[i] + 1);
    }
    printf("\n");
    firstTime = true;
    for (int i = 0; i < (int)(T); ++i) {
      if (!firstTime) {
        printf(" ");
      }
      firstTime = false;
      printf("%d", col[i] + 1);
    }
    printf("\n");
    break;
  }
  return 0;
}
