#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 100;
int n, m, u, v, T, cnt[N], team[N];
bool part[N];
vector<int> vec[N];
vector<pair<int, int> > edge;
int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  srand(time(0));
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> u >> v;
    edge.push_back(pair<int, int>(--u, --v));
  }
  for (int i = 0; i < n; i++) {
    cin >> cnt[i];
    for (int j = 0; j < cnt[i]; j++) {
      cin >> u;
      T = max(T, u);
      vec[i].push_back(--u);
    }
  }
  while (true) {
    for (int i = 0; i < n; i++) team[i] = vec[i][rand() % cnt[i]];
    for (int i = 0; i < T; i++) part[i] = rand() & 1;
    int CNT = 0;
    for (pair<int, int> p : edge)
      CNT += (part[team[p.first]] ^ part[team[p.second]]);
    if (2 * CNT >= m) {
      for (int i = 0; i < n; i++) cout << team[i] + 1 << ' ';
      cout << '\n';
      for (int i = 0; i < T; i++) cout << part[i] + 1 << ' ';
      return 0;
    }
  }
  return 0;
}
