using System;
using System.Collections.Generic;
using System.Text;

class Program
{

    public void Proc()
    {
        int comandCount = int.Parse(Console.ReadLine());
        for (int i = 0; i < comandCount; i++)
        {
            long target = 0;
            string cmd;
            string[] inpt = Console.ReadLine().Split(' ');
            cmd = inpt[0];
            if (inpt.Length >= 2)
            {
                target = long.Parse(inpt[1]);
            }


            if (cmd.StartsWith("insert"))
            {
                TreeNd.Insert(target);
            }
            else
            {
                TreeNd.PrintAll();
            }

        }
    }

    public class TreeNd
    {
        private static TreeNd Root = null;
        /// <summary>
        /// ??????
        /// </summary>
        /// <param name="insKey"></param>
        public static void Insert(long insKey)
        {
            if (Root == null)
            {
                Root = new TreeNd(insKey);
            }
            else
            {
                Root.Add(insKey);
            }
        }

        public static void PrintAll()
        {
            if (Root == null)
            {
                return;
            }
            Root.PrintInorder();
            Console.WriteLine("");
            Root.PringPreorder();
            Console.WriteLine("");
        }


        public void PringPreorder()
        {
            Console.Write(" ");
            Console.Write(this.Key);
            if (this.LeftChild != null)
            {
                this.LeftChild.PringPreorder();
            }
            if (this.RightChild != null)
            {
                this.RightChild.PringPreorder();
            }
        }
        public void PrintInorder()
        {
            if (this.LeftChild != null)
            {
                this.LeftChild.PrintInorder();
            }
            Console.Write(" ");
            Console.Write(this.Key);
            if (this.RightChild != null)
            {
                this.RightChild.PrintInorder();
            }
        }

        /// <summary>
        /// ??????
        /// </summary>
        /// <param name="addKey"></param>
        public void Add(long addKey)
        {
            if (addKey < this.Key)
            {
                if (this.LeftChild == null)
                {
                    this.LeftChild = new TreeNd(addKey);
                    this.LeftChild.Parent = this;
                }
                else
                {
                    this.LeftChild.Add(addKey);
                }
            }
            else
            {
                if (this.RightChild == null)
                {
                    this.RightChild = new TreeNd(addKey);
                    this.RightChild.Parent = this;
                }
                else
                {
                    this.RightChild.Add(addKey);
                }
            }
        }

        public TreeNd(long newKey)
        {
            this.Key = newKey;
        }
        public long Key;
        public TreeNd Parent = null;
        public TreeNd LeftChild = null;
        public TreeNd RightChild = null;
    }




    static void Main(string[] args)
    {
        Program prg = new Program();
        prg.Proc();
    }
}

Measured memory_bytes: 47228