public static void main(String[] args) {
        int n, m, x, y;
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        m = sc.nextInt();
        int id[] = new int[n];
        
        QuickUnion QU = new QuickUnion(n);
        QuickFind QF = new QuickFind(n);
        WeightedQuickUnion WQU = new WeightedQuickUnion(n);
        
        for (int i = 0; i < m; i++) {
            x = sc.nextInt();
            y = sc.nextInt();
            WQU.union(x, y);
            id = WQU.getIds();
            for (int j = 0; j < n; j++) {
                System.out.print(id[j]);
                System.out.print(' ');
            }
            System.out.println();
        }
        
    }