Problem: Welcome to the world of Pokermon, yellow little mouse-like creatures, who absolutely love playing poker! 

Yeah, right… 

In the ensuing Pokermon League, there are n registered Pokermon trainers, and t existing trainer teams each of which belongs to one of two conferences. Since there is a lot of jealousy between trainers, there are e pairs of trainers who hate each other. Their hate is mutual, there are no identical pairs among these, and no trainer hates himself (the world of Pokermon is a joyful place!). Each trainer has a wish-list of length li of teams he’d like to join.

Your task is to divide players into teams and the teams into two conferences, so that: 

  * each trainer belongs to exactly one team; 
  * no team is in both conferences; 
  * total hate between conferences is at least e / 2; 
  * every trainer is in a team from his wish-list. 



Total hate between conferences is calculated as the number of pairs of trainers from teams from different conferences who hate each other. 

Input

The first line of the input contains two integer n (4 ≤ n ≤ 50 000) and e (2 ≤ e ≤ 100 000) — the total number of Pokermon trainers and the number of pairs of trainers who hate each other.

Pokermon trainers are numbered from 1 to n. Next e lines contain two integers a and b (1 ≤ a, b ≤ n) indicating that Pokermon trainers a and b hate each other. Next 2n lines are in a following format. Starting with Pokermon trainer 1, for each trainer in consecutive order: first number li (16 ≤ li ≤ 20) — a size of Pokermon trainers wish list, then li positive integers ti, j (1 ≤ ti, j ≤ T), providing the teams the i-th trainer would like to be on.

Each trainers wish list will contain each team no more than once. Teams on the wish lists are numbered in such a way that the set of all teams that appear on at least 1 wish list is set of consecutive positive integers {1, 2, 3, …, T}. Here T might be up to 1 000 000.

Output

Print two lines. The first line should contain n numbers, specifying for each trainer the team he is in.

The second line should contain T numbers, specifying the conference for each team (1 or 2).

Example

Input

4 3
1 2
2 3
4 1
16
1 2 3 4 5 6 7 8 9 10 11 12 13 14 16 15
16
2 3 4 5 6 7 8 9 10 11 12 13 14 15 17 18
16
2 3 4 5 6 7 8 9 10 11 12 13 14 15 18 19
16
1 2 3 4 5 6 7 8 9 10 11 12 13 14 16 19


Output

16 15 19 14 
2 2 2 1 1 1 2 1 1 2 1 1 1 2 2 1 1 1 1 

Note

Solution (in JAVA):

Solution:
import java.awt.Point;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.StringTokenizer;

public class H {

    BufferedReader in;
    PrintWriter out;
    StringTokenizer tok;

    void init() {
        try {
            in = new BufferedReader(new FileReader("input.txt"));
            out = new PrintWriter("output.txt");
        } catch (Exception e) {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
        }
    }

    String readString() {
        try {
            while (tok == null || !tok.hasMoreTokens()) {
                tok = new StringTokenizer(in.readLine());
            }
            return tok.nextToken();
        } catch (Exception e) {
            return null;
        }
    }

    int readInt() {
        return Integer.parseInt(readString());
    }

    long readLong() {
        return Long.parseLong(readString());
    }

    int[] readIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = readInt();
        }
        return a;
    }

    public static void main(String[] args) {
        new H().run();
    }

    void run() {
        try {
            long tStart = System.currentTimeMillis();
            init();
            solve();
            in.close();
            out.close();
            long tEnd = System.currentTimeMillis();

            System.err.println(tEnd - tStart);
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(-1);
        }
    }

    void solve() {
        int trainersCount = readInt();
        int edgesCount = readInt();

        Point[] edges = new Point[edgesCount];
        for (int i = 0; i < edgesCount; ++i) {
            int from = readInt() - 1;
            int to = readInt() - 1;
            edges[i] = new Point(from, to);
        }

        List<Integer>[] trainersTeams = new List[trainersCount];
        int teamsCount = 0;

        for (int i = 0; i < trainersCount; ++i){
            int size = readInt();
            List<Integer> trainerTeams = new ArrayList<>(size);

            for (int j = 0; j < size; ++j) {
                int team = readInt() - 1;
                teamsCount = Math.max(teamsCount, team + 1);

                trainerTeams.add(team);
            }

            trainersTeams[i] = trainerTeams;
        }

        Random rnd = new Random();

        int[] mappedTeams = new int[trainersCount];
        boolean[] isEnemyConferences = new boolean[teamsCount];

        while (true) {
            for (int trainer = 0; trainer < trainersCount; ++trainer) {
                List<Integer> trainerTeams = trainersTeams[trainer];
                int trainerTeamIndex = rnd.nextInt(trainerTeams.size());
                mappedTeams[trainer] = trainerTeams.get(trainerTeamIndex);
            }

            for (int team = 0; team < teamsCount; ++team) {
                isEnemyConferences[team] = rnd.nextBoolean();
            }

            int enemyEdgesCount = 0;
            for (Point edge : edges) {
                int fromTeam = mappedTeams[edge.x];
                int toTeam = mappedTeams[edge.y];
                if (isEnemyConferences[fromTeam] != isEnemyConferences[toTeam]) {
                    ++enemyEdgesCount;
                }
            }

            if (enemyEdgesCount * 2 >= edgesCount) {
                break;
            }
        }

        for (int mappedTeam : mappedTeams) {
            out.print((mappedTeam + 1) + " ");
        }
        out.println();

        for (boolean isEnemyConference : isEnemyConferences) {
            int conference = (isEnemyConference ? 1 : 2);
            out.print(conference + " ");
        }
        out.println();
    }
}