Misha hacked the Codeforces site. Then he decided to let all the users change their handles. A user can now change his handle any number of times. But each new handle must not be equal to any handle that is already used or that was used at some point.

Misha has a list of handle change requests. After completing the requests he wants to understand the relation between the original and the new handles of the users. Help him to do that.

Input

The first line contains integer q (1 ≤ q ≤ 1000), the number of handle change requests.

Next q lines contain the descriptions of the requests, one per line.

Each query consists of two non-empty strings old and new, separated by a space. The strings consist of lowercase and uppercase Latin letters and digits. Strings old and new are distinct. The lengths of the strings do not exceed 20.

The requests are given chronologically. In other words, by the moment of a query there is a single person with handle old, and handle new is not used and has not been used by anyone.

Output

In the first line output the integer n — the number of users that changed their handles at least once.

In the next n lines print the mapping between the old and the new handles of the users. Each of them must contain two strings, old and new, separated by a space, meaning that before the user had handle old, and after all the requests are completed, his handle is new. You may output lines in any order.

Each user who changes the handle must occur exactly once in this description.

Examples

Input

5
Misha ILoveCodeforces
Vasya Petrov
Petrov VasyaPetrov123
ILoveCodeforces MikeMirzayanov
Petya Ivanov


Output

3
Petya Ivanov
Misha MikeMirzayanov
Vasya VasyaPetrov123

import java.io.IOException;

import java.util.StringTokenizer;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.MathContext;
import java.util.ArrayList;
import java.util.Collections;
import java.util.TreeSet;
import java.util.*;

public class  Main {

    
    public static void main(String[]args)
    {
      FastReader in=new FastReader();
      
      int n=in.nextInt();
      
      ArrayList p=new ArrayList();
      
      ArrayList p2=new ArrayList();
      
      ArrayList p3=new ArrayList();
      int i=0;
      while(n-->0)
      {
          String s=in.next();
          
          String x=in.next();
          
          if((!p.contains(s)) && (!p2.contains(s)) && (!p2.contains(x)) && !p.contains(x))
          {
             p.add(s);
             p2.add(x);
          }
          else if(p2.contains(s)) //&& p3.contains(s))
           {
                if(!p2.contains(x))
                {
                    int c=p2.indexOf(s);
                    p3.add(s);
                    p2.remove(c);
                    p2.add(c,x);
                }
          }
          
      }
      
      StringBuilder e=new StringBuilder();
      while(i<p.size())
      {
          e.append(p.get(i));
          
          String[]m=((String)p2.get(i)).split(" ");
          
          e.append(" "+m[m.length-1]+"\n");
          
          i++;
      }
      
        System.out.print(i+"\n"+e);
      
    }
    
}




    

    
/* longest common subsequence

Scanner in=new Scanner(System.in);
        
      while(in.hasNextLine()){
      String s=in.next();
      
      String x=in.next();
      
      int l1=s.length();
      
      int l2=x.length();
      
      int[][]e=new int[l1+1][l2+1];
      
      for(int i=0;i<l1+1;i++)
      {
         for(int y=0;y<l2+1;y++)
         {
             if(i==0 || y==0)
             {
                 e[i][y]=0;
             }
             
             else{
             if(s.charAt(i-1)==x.charAt(y-1))
             {
                 e[i][y]=e[i-1][y-1]+1;
             }
             else
             {
                 e[i][y]=Math.max(e[i-1][y],e[i][y-1]);
             }
            }
         }
      }
      
        System.out.println(e[l1][l2]);

*/




//method for prime numbers

/*public static boolean sieve(int n) {
    boolean[]x=new boolean[n+1];
    for(int i = 0; i <= n;++i) {
        x[i] = true;
    }
    x[0] = false;
    x[1] = false;
    for(int i = 2; i * i <= n; ++i) {
         if(x[i] == true) {
             // Mark all the multiples of i as composite numbers
             for(int j = i * i; j <= n ;j += i)
                 x[j] = false;
        }
    }
    
    int i=0;
    
    int count=0;
    while(i<x.length)
    {
        if(x[i] && n%i==0)
            count++;
        
        i++;
    }
    
    return (count==3)?true:false;*/




/* monk is birthday treat

int n=in.nextInt();
       
       int t=in.nextInt();
       
       s=new List[n];
       
       for(int r=0;r<s.length;r++)
       {
           s[r]=new ArrayList();
       }
       
       
       while(t-->0)
       {
           int a=in.nextInt()-1;
           
           int b=in.nextInt()-1;
           s[a].add(b);
       }
       
       long[]p=new long[n];
       
       for(int i=0;i<s.length;i++)
       {
          
          Stack<Integer>e=new Stack();
          int[]k=new int[s[i].size()];
          int j=0;
          if(!s[i].isEmpty()){
              
              boolean []x=new boolean[n]; 
              
           for (Integer h : s[i]) {
               int count=0;
              
               e.add(h);
               
               if(!x[h]){
               x[h]=true;
               count++;
               }
               while(!e.isEmpty())
               {
                   int u=e.pop();
                   
                   for (Integer v : s[u]) {
                       if(!x[v])
                       {
                           x[v]=true;
                           count++;
                           e.add(v);
                       }
                       
                   }
                   
               }
               
               k[j]=count;
               j++;
               
           }
        Arrays.sort(k);
        
        int q=0;
        while(q<k.length)
        {
            if(k[q]!=0)
            {
                p[i]=k[q];
                break;
            }
            q++;
        }
        
        
          }
       }
        Arrays.sort(p);
        int y=0;
        long count2=0;
        while(y<p.length)
        {
           if(p[y]!=0)
           {
              count2=p[y];
              break;
           }
           
           y++;
        }
        System.out.println(count2);

*/

/*class Reader
    {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;
 
        public Reader()
        {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }
 
        public Reader(String file_name) throws IOException
        {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }
 
        public String readLine() throws IOException
        {
            byte[] buf = new byte[64]; // line length
            int cnt = 0, c;
            while ((c = read()) != -1)
            {
                if (c == '\n')
                    break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }
 
        public int nextInt() throws IOException
        {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do
            {
                ret = ret * 10 + c - '0';
            }  while ((c = read()) >= '0' && c <= '9');
 
            if (neg)
                return -ret;
            return ret;
        }
 
        public long nextLong() throws IOException
        {
            long ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }
 
        public double nextDouble() throws IOException
        {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
 
            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');
 
            if (c == '.')
            {
                while ((c = read()) >= '0' && c <= '9')
                {
                    ret += (c - '0') / (div *= 10);
                }
            }
 
            if (neg)
                return -ret;
            return ret;
        }
 
        private void fillBuffer() throws IOException
        {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }
 
        private byte read() throws IOException
        {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }
 
        public void close() throws IOException
        {
            if (din == null)
                return;
            din.close();
        }
}*/

class FastReader
    {
        BufferedReader br;
        StringTokenizer st;
 
        public FastReader()
        {
            br = new BufferedReader(new
                     InputStreamReader(System.in));
        }
 
        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
 
        int nextInt()
        {
            return Integer.parseInt(next());
        }
 
        long nextLong()
        {
            return Long.parseLong(next());
        }
 
        double nextDouble()
        {
            return Double.parseDouble(next());
        }
 
        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
}