import java.util.Scanner;

// Node class for Linked List
class Node {
    String name;
    Node next;

    Node(String name) {
        this.name = name;
        this.next = null;
    }
}

public class LibraryVisitors {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        sc.nextLine();  // consume newline

        Node head = null; 
        Node tail = null;   // maintain tail pointer
        boolean invalid = false;

        // Reading visitor names
        for (int i = 0; i < n; i++) {
            String name = sc.nextLine().trim();

            // Validate: only alphabets allowed
            if (!name.matches("[a-zA-Z]+")) {
                invalid = true;
            }

            // Create a new node
            Node newNode = new Node(name);

            if (head == null) {  // first node
                head = newNode;
                tail = newNode;
            } else {             // add at the tail
                tail.next = newNode;
                tail = newNode;
            }
        }

        if (invalid) {
            System.out.println("Invalid input");
        } else {
            // Traverse and print the linked list
            Node current = head;
            while (current != null) {
                System.out.print(current.name);
                if (current.next != null) {
                    System.out.print(" ");
                }
                current = current.next;
            }
        }

        sc.close();
    }
}