#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
const int N = 1e5 + 10, INF = 0x3f3f3f3f, MOD = 1e9 + 7;
int n, m;
vector<int> lists[N];
vector<pair<int, int> > hate;
int conf[N * 10], team[N];
int main() {
  ios_base::sync_with_stdio(0);
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    hate.push_back({u, v});
  }
  int T = -INF;
  for (int i = 1; i <= n; ++i) {
    int k;
    scanf("%d", &k);
    while (k--) {
      int x;
      scanf("%d", &x);
      lists[i].push_back(x);
      T = max(T, x);
    }
  }
  srand(12345);
  int ok = false;
  while (!ok) {
    for (int i = 1; i <= T; ++i) conf[i] = rand() & 1;
    for (int i = 1; i <= n; ++i) team[i] = lists[i][rand() % lists[i].size()];
    int hatred = 0;
    for (int i = 0; i < m && !ok; ++i) {
      int u, v;
      tie(u, v) = hate[i];
      hatred += conf[team[u]] ^ conf[team[v]];
      if (hatred * 2 >= m) ok = true;
    }
  }
  for (int i = 1; i <= n; ++i) printf("%d%c", team[i], " \n"[i == n]);
  for (int i = 1; i <= T; ++i) printf("%d%c", conf[i] + 1, " \n"[i == T]);
  return 0;
}
