#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
int n, m, c[50005], l[50005][25], T, t[50005], con[1000005];
pair<int, int> ed[100005];
int main() {
  srand((unsigned)time(NULL));
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> ed[i].first >> ed[i].second;
    ed[i].first--;
    ed[i].second--;
  }
  for (int i = 0; i < n; i++) {
    cin >> c[i];
    for (int j = 0; j < c[i]; j++) {
      cin >> l[i][j];
      l[i][j]--;
      T = max(T, l[i][j]);
    }
  }
  int cnt;
  do {
    for (int i = 0; i <= T; i++) {
      con[i] = (rand() & 1) + 1;
    }
    for (int i = 0; i < n; i++) {
      t[i] = l[i][rand() * rand() % c[i]];
    }
    cnt = 0;
    for (int i = 0; i < m; i++) {
      cnt += (con[t[ed[i].first]] != con[t[ed[i].second]]);
    }
  } while (cnt * 2 < m);
  for (int i = 0; i < n; i++) {
    cout << t[i] + 1 << ' ';
  }
  cout << endl;
  for (int i = 0; i <= T; i++) {
    cout << con[i] << ' ';
  }
  return 0;
}
