#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 9;
int n, m, b[MAX], a[MAX], mx, c[MAX];
vector<int> g[MAX], t;
set<int> s[MAX];
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0), srand(time(NULL));
  cin >> n >> m;
  for (int i = 0, v, u; i < m; i++)
    cin >> v >> u, v--, u--, g[v].push_back(u), g[u].push_back(v);
  for (int k = 0; k < 10; k++)
    for (int i = 0; i < n; i++) {
      int k = 0;
      for (auto u : g[i]) k += (b[u] == b[i]);
      if (k * 2 > g[i].size()) b[i] ^= 1;
    }
  for (int i = 0; i < n; i++) {
    int l, x;
    cin >> l;
    while (l--) cin >> x, s[x].insert(i), t.push_back(x), mx = max(mx, x);
  }
  sort(t.begin(), t.end()), t.resize(unique(t.begin(), t.end()) - t.begin());
  for (int k = 0; k < 10; k++) {
    memset(a, 0, sizeof a);
    for (auto i : t) {
      rand(), rand();
      int l = rand() % 2;
      c[i] = l;
      for (auto j : s[i])
        if (b[j] == l) a[j] = i;
    }
    bool flg = true;
    for (int i = 0; i < n; i++) flg &= (a[i] != 0);
    if (flg) {
      for (int i = 0; i < n; i++) cout << a[i] << ' ';
      cout << '\n';
      for (int i = 1; i <= mx; i++) cout << c[i] + 1 << ' ';
      return 0;
    }
  }
}
