package main

import (
	"bufio"
	"bytes"
	"fmt"
	"io"
	"os"
	"strconv"
)

var DEBUG = true

func main() {
	defer Flush()

	N := readi()
	Q := readi()
	L := make([]*List, N)
	for i := range L {
		L[i] = NewList()
	}
	for q := 0; q < Q; q++ {
		tp := readi()
		switch tp {
		case 0:
			t := readi()
			x := readi()
			//dbg("> 0", t, x)
			L[t].PushTail(x)
		case 1:
			t := readi()
			//dbg("> 1", t)
			sp := ""
			for nd := L[t].Head(); nd != nil; nd = nd.Next() {
				printf("%s%d", sp, nd.Get().(int))
				sp = " "
			}
			println()
		default:
			s := readi()
			t := readi()
			//dbg("> 2", s, t)
			L[t].Splice(nil, L[s])
		}
		//for i := range L {
		//	dbg(q, i, L[i])
		//}
		//dbg()
	}
}

type ListNode struct {
	val        interface{}
	prev, next *ListNode
}

func (nd *ListNode) Next() *ListNode {
	return nd.next
}

func (nd *ListNode) Prev() *ListNode {
	return nd.prev
}

func (nd *ListNode) Get() interface{} {
	return nd.val
}

func (nd *ListNode) Set(val interface{}) {
	nd.val = val
}

type List struct {
	size int
	head *ListNode
	tail *ListNode
}

func NewList() *List {
	return &List{}
}

func (l *List) Len() int {
	return l.size
}

func (l *List) Head() *ListNode {
	return l.head
}

func (l *List) Tail() *ListNode {
	return l.tail
}

func (l *List) HeadValue() interface{} {
	if l.size == 0 {
		panic("empty list")
	}
	return l.head.val
}

func (l *List) TailValue() interface{} {
	if l.size == 0 {
		panic("empty list")
	}
	return l.tail.val
}

func (l *List) Insert(pos *ListNode, nd *ListNode) *ListNode {
	if nd == nil {
		panic("inserting nil")
	}

	if l.head == nil {
		// adding the first node
		l.head = nd
		l.head.prev = nil
		l.tail = nd
		l.tail.next = nil
	} else if pos == l.head {
		// adding the node as the head
		l.head = nd
		l.head.prev = nil
		nd.next = pos
		pos.prev = nd
	} else if pos == nil {
		// pos==nil means inserting the node as the tail
		l.tail.next = nd
		nd.prev = l.tail
		nd.next = nil
		l.tail = nd
	} else {
		prev := pos.prev
		next := pos

		nd.prev = prev
		prev.next = nd

		nd.next = next
		next.prev = nd
	}

	l.size++
	return nd
}

func (l *List) InsertValue(pos *ListNode, v interface{}) *ListNode {
	nd := &ListNode{
		val: v,
	}
	inserted := l.Insert(pos, nd)
	return inserted
}

func (l *List) Remove(pos *ListNode) *ListNode {
	if l.size == 0 {
		panic("empty list")
	}
	if pos == nil {
		panic("removing invalid node")
	} else if pos.prev == nil && pos.next == nil {
		l.head = nil
		l.tail = nil
		l.size--
		return nil
	} else if pos == l.head {
		// removing head
		l.head = pos.next
		l.head.prev = nil
		l.size--
		return l.head
	} else if pos == l.tail {
		// removing tail
		l.tail = pos.prev
		l.tail.next = nil
		l.size--
		return nil
	}

	prev := pos.prev
	next := pos.next
	prev.next = next
	next.prev = prev
	l.size--
	return next
}

func (l *List) PushHead(v interface{}) {
	nd := &ListNode{
		val: v,
	}
	l.Insert(l.head, nd)
}

func (l *List) PopHead() interface{} {
	nd := l.head
	l.Remove(nd)
	return nd.val
}

func (l *List) PushTail(v interface{}) {
	nd := &ListNode{
		val: v,
	}
	l.Insert(nil, nd)
}

func (l *List) PopTail() interface{} {
	nd := l.tail
	l.Remove(nd)
	return nd.val
}

func (l *List) Swap(r *List) {
	tmp := NewList()
	tp := tmp.head
	tmp.Splice(tp, r)

	rp := r.head
	r.Splice(rp, l)

	lp := l.head
	l.Splice(lp, tmp)
}

func (l *List) Clear() {
	l.size = 0
	l.head = nil
	l.tail = nil
}

func (l *List) RemoveIf(pred func(v interface{}) bool) {
	for i := l.head; i != nil; {
		if pred(i.val) {
			i = l.Remove(i)
		} else {
			i = i.next
		}
	}
}

func (l *List) Unique(eql func(v, u interface{}) bool) {
	if l.head == nil {
		return
	}

	if l.head.next == nil {
		// already unique
		return
	}

	for cur, next := l.head, l.head.next; next != nil; {
		if eql(cur.val, next.val) {
			next = l.Remove(next)
		} else {
			cur = next
			next = next.next
		}
	}
}

func (l *List) Merge(x *List, less func(v, u interface{}) bool) {
	nh, nt := l.head.merge(x.head, less)
	l.head = nh
	l.tail = nt
	l.size += x.size
	x.Clear()
}

func (nd *ListNode) merge(x *ListNode, less func(v, u interface{}) bool) (*ListNode, *ListNode) {
	head := &ListNode{}
	cur := head
	i, j := nd, x
	for i != nil && j != nil {
		if less(i.val, j.val) {
			cur.next = i
			i.prev = cur
			cur = cur.next
			i = i.next
		} else {
			cur.next = j
			j.prev = cur
			cur = cur.next
			j = j.next
		}
	}
	if i == nil && j != nil {
		cur.next = j
		j.prev = cur
	}
	if i != nil && j == nil {
		cur.next = i
		i.prev = cur
	}

	for cur.next != nil {
		cur = cur.next
	}
	if cur == head {
		cur = nil
	}

	head.next.prev = nil
	return head.next, cur
}

func (l *List) String() string {
	var s string
	s = "("
	sp := ""

	for i := l.head; i != nil; i = i.next {
		s = fmt.Sprintf("%s%s%d", s, sp, i.val)
		sp = ", "
	}
	s += ")"
	return s
}

func (l *List) Sort(less func(v, u interface{}) bool) {
	if l.size <= 1 {
		return
	}

	q := make([][2]*ListNode, 0)
	push := func(x, y *ListNode) {
		q = append(q, [2]*ListNode{x, y})
	}
	pop := func() (*ListNode, *ListNode) {
		x := q[0]
		q = q[1:]
		return x[0], x[1]
	}

	for i := l.head; i != nil; {
		j := i
		i = i.next
		j.prev = nil
		j.next = nil
		push(j, j)
	}

	for len(q) != 1 {
		x, _ := pop()
		y, _ := pop()
		push(x.merge(y, less))
	}

	nh, nt := pop()
	l.head = nh
	l.tail = nt
}

func (l *List) Splice(pos *ListNode, x *List) {
	if x.size == 0 {
		return
	}

	if l.head == nil {
		l.head = x.head
		l.tail = x.tail
	} else if pos == l.head {
		l.head = x.head
		x.tail.next = pos
		pos.prev = x.tail
	} else if pos == nil {
		l.tail.next = x.head
		x.head.prev = l.tail
		l.tail = x.tail
	} else {
		prev := pos.prev
		next := pos

		first := x.head
		last := x.tail

		first.prev = prev
		prev.next = first

		last.next = next
		next.prev = last
	}
	l.size += x.size
	x.Clear()
}

// -----------------------------------------------------------------------------

// IO helper functions

// Returns next token from input.  It must be initialized by SetInput()
// before the first call.
var nextToken func() ([]byte, error)
var nextLine func() ([]byte, error)

// Holds a buffer for output.  It must be initialized by SetOutput().
// All IO fucntions (read*() and [e]print*()) should write to OutputWriter
// instead of this.
var OutputBuffer *bufio.Writer

// Holds an io.Writer.  It must be initialized by SetOutput()
var OutputWriter io.Writer

// Set IO functions for interactive input/output.
func SetInteractive(w io.Writer, r io.Reader) {
	SetUnbefferedInput(r)
	OutputBuffer = nil
	OutputWriter = w
}

// Setup OutputBuffer and OutputWriter.
func SetOutput(w io.Writer) {
	OutputBuffer = bufio.NewWriter(w)
	OutputWriter = OutputBuffer
}

// Flushes OutputBuffer
func Flush() {
	if OutputBuffer != nil {
		OutputBuffer.Flush()
	}
}

// Returns true if c is a white space
func IsSpace(c byte) bool {
	switch c {
	case '\t', '\n', '\v', '\f', '\r', ' ':
		return true
	}
	return false
}

func IsNewLine(c byte) bool {
	switch c {
	case '\n', '\r':
		return true
	}
	return false
}

// Setup nextToken with input buffer.
func SetInput(r io.Reader) {
	buf := new(bytes.Buffer)
	var b []byte

	var i int
	rest := func() ([]byte, error) {
		for i < len(b) && IsSpace(b[i]) {
			i++
		}
		if i == len(b) {
			return nil, io.ErrUnexpectedEOF
		}
		j := i
		for i < len(b) && !IsSpace(b[i]) {
			i++
		}
		return b[j:i], nil
	}
	initial := func() ([]byte, error) {
		io.Copy(buf, r)
		b = buf.Bytes()
		nextToken = rest
		return rest()
	}
	nextToken = initial

	restLn := func() ([]byte, error) {
		for i < len(b) && IsNewLine(b[i]) {
			i++
		}
		if i == len(b) {
			return nil, io.ErrUnexpectedEOF
		}
		j := i
		for i < len(b) && !IsNewLine(b[i]) {
			i++
		}
		return b[j:i], nil
	}

	initialLn := func() ([]byte, error) {
		io.Copy(buf, r)
		b = buf.Bytes()
		nextLine = restLn
		return restLn()
	}
	nextLine = initialLn
}

// Setup nextToken without input buffer.
func SetUnbefferedInput(r io.Reader) {
	buf := bufio.NewReader(r)
	var b []byte

	var i int
	nextToken = func() ([]byte, error) {
		var err error
		if i == len(b) {
			b, err = buf.ReadBytes('\n')
			if err != nil {
				return nil, err
			}
			i = 0
			j := len(b) - 1
			for 0 <= j && IsSpace(b[j]) {
				j--
			}
			b = b[0 : j+1]
		}
		for i < len(b) && IsSpace(b[i]) {
			i++
		}
		j := i
		for i < len(b) && !IsSpace(b[i]) {
			i++
		}
		if i == j {
			return nil, io.ErrUnexpectedEOF
		}
		return b[j:i], nil
	}
}

// -----------------------------------------------------------------------------

// IO functions

// Reads next token and return it as []byte
func readb() []byte {
	b, err := nextToken()
	if err != nil {
		panic(err)
	}
	return b[:len(b):len(b)]
}

// Reads next token and return it as string
func reads() string {
	return string(readb())
}

// Read next line as []byte.  Trailing '\n' will not be included.
// See also comments on readb()
func readbln() []byte {
	b, err := nextLine()
	if err != nil {
		panic(err)
	}
	return b[:len(b):len(b)]
}

// Read next line as string
func readsln() string {
	return string(readbln())
}

// Reads next token and return it as int64
func readll() int64 {
	i, err := strconv.ParseInt(reads(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// Reads next token and return it as int
func readi() int {
	return int(readll())
}

// Reads next token and return it as float64
func readf() float64 {
	f, err := strconv.ParseFloat(reads(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// Write args to OutputWriter with the format f
func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(OutputWriter, f, args...)
}

// Write args to OutputWriter without format
func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(OutputWriter, args...)
}

// Write args to stderr with the format f
func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

// Write args to stderr without format
func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

func dbgf(f string, args ...interface{}) {
	if !DEBUG {
		return
	}
	fmt.Fprintf(os.Stderr, f, args...)
}

func dbg(args ...interface{}) {
	if !DEBUG {
		return
	}
	fmt.Fprintln(os.Stderr, args...)
}

// -----------------------------------------------------------------------------

// Utilities

func sumSlice(a []int) int {
	var res int
	for _, v := range a {
		res += v
	}
	return res
}

func sumSlicell(a []int64) int64 {
	var res int64
	for _, v := range a {
		res += v
	}
	return res
}

func readInts(N int) (int, []int) {
	if N == 0 {
		N = readi()
	}
	a := make([]int, N)
	for i := range a {
		a[i] = readi()
	}
	return N, a
}

func readIntsll(N int) (int, []int64) {
	if N == 0 {
		N = readi()
	}
	a := make([]int64, N)
	for i := range a {
		a[i] = readll()
	}
	return N, a
}

// -----------------------------------------------------------------------------

// Simple math functions

const (
	// big prime
	INF  = 1000000007
	INF2 = 1000000009
	INF3 = 998244353
)

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func minll(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func minf(a, b float64) float64 {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func maxll(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func maxf(a, b float64) float64 {
	if a < b {
		return b
	}
	return a
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func absll(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

func absf(a float64) float64 {
	if a < 0 {
		return -a
	}
	return a
}

// egcd(a, b) returns d, x, y:
//   d is gcd(a,b)
//   x, y are  integers that satisfy ax + by = d
func egcd(a, b int) (int, int, int) {
	if b == 0 {
		return a, 1, 0
	}
	d, x, y := egcd(b, a%b)
	return d, y, x - a/b*y
}

func egcdll(a, b int64) (int64, int64, int64) {
	if b == 0 {
		return a, 1, 0
	}
	d, x, y := egcdll(b, a%b)
	return d, y, x - a/b*y
}

func gcd(a, b int) int {
	d, _, _ := egcd(a, b)
	return d
}

func gcdll(a, b int64) int64 {
	d, _, _ := egcdll(a, b)
	return d
}

// set up IO functions
func init() {
	// for non-interactive
	SetInput(os.Stdin)
	SetOutput(os.Stdout)

	// Enable below when interactive.  Its ok to leave above intact.
	// SetInteractive(os.Stdout, os.Stdin)
}



Measured memory_bytes: 46424