#include <bits/stdc++.h>
using namespace std;
const int N = 5e4 + 10;
const int TEAM = 1e6 + 10;
int team[N], comp[TEAM], hate[2 * N][2], len[N], whish[N][21];
int n, e, T;
bool solve() {
  int total = 0;
  for (int i = 1; i <= n; i++) team[i] = whish[i][rand() % len[i]];
  for (int i = 1; i <= T; i++) comp[i] = rand() % 2 + 1;
  for (int i = 0; i < e; i++)
    total += comp[team[hate[i][0]]] != comp[team[hate[i][1]]];
  return (2 * total >= e);
}
int main() {
  scanf("%d%d", &n, &e);
  for (int i = 0; i < e; i++) scanf("%d%d", hate[i], hate[i] + 1);
  for (int i = 1; i <= n; i++) {
    scanf("%d", len + i);
    for (int j = 0; j < len[i]; j++) {
      scanf("%d", whish[i] + j);
      T = max(T, whish[i][j]);
    }
  }
  while (!solve())
    ;
  for (int i = 1; i <= n; i++) printf("%d ", team[i]);
  puts("");
  for (int i = 1; i <= T; i++) printf("%d ", comp[i]);
  return 0;
}
