#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1000000000")
using namespace std;
const int maxn = (int)5e4 + 10;
vector<int> ed[maxn];
int cl[maxn];
vector<int> edd[maxn];
int z[maxn];
int ans[maxn];
int main() {
  int n, e;
  cin >> n >> e;
  for (int i = 0; i < e; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    ed[x].push_back(y);
    ed[y].push_back(x);
  }
  for (int i = 1; i <= n; i++) {
    int cnt = 0;
    for (int j = 0; j < (int)ed[i].size(); j++) {
      int u = ed[i][j];
      if (u < i) {
        if (cl[u] == 1) {
          cnt++;
        } else {
          cnt--;
        }
      }
    }
    if (cnt > 0) {
      cl[i] = 2;
    } else {
      cl[i] = 1;
    }
  }
  int t = 0;
  for (int i = 1; i <= n; i++) {
    int cnt;
    scanf("%d", &cnt);
    for (int j = 0; j < cnt; j++) {
      int x;
      scanf("%d", &x);
      t = max(t, x);
      edd[i].push_back(x);
    }
  }
  while (true) {
    for (int i = 1; i <= t; i++) {
      z[i] = 1;
      if (rand() & 1) {
        z[i] = 2;
      }
    }
    bool st = true;
    for (int i = 1; i <= n; i++) {
      bool good = false;
      for (int j = 0; j < (int)edd[i].size(); j++) {
        int u = edd[i][j];
        if (z[u] == cl[i]) {
          ans[i] = u;
          good = true;
          break;
        }
      }
      if (!good) {
        st = false;
        break;
      }
    }
    if (st) {
      break;
    }
  }
  for (int i = 1; i <= n; i++) {
    printf("%d ", ans[i]);
  }
  printf("\n");
  for (int i = 1; i <= t; i++) {
    printf("%d ", z[i]);
  }
  return 0;
}
