#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#define LEN 30

char * sgets(char *, int);

struct book {
    char title[LEN];
    char author[LEN];
    char id;
};

typedef struct book Item;

typedef struct node {
    Item item;
    struct node * next;
} Node;

int main(void)
{
    Node * head;
    Node * prev, * current;


    while (1)
    {
        current = malloc(sizeof *current);
        
        if (head == NULL)
            head = current;
        else
            prev->next = current;

        if (sgets(current->item.author, LEN) == NULL || current->item.author[0] == '\0')
        {
            current = NULL;
            break;
        }

        if (sgets(current->item.title, LEN) == NULL || current->item.title[0] == '\0')
        {
            current = NULL;
            break;
        }

        if (scanf("%hhd", &current->item.id) != 1)
        {
            current = NULL;
            break;
        }
        while (getchar() != '\n')
            continue;

        current->next = NULL;

        prev = current;
    }

    current = head;

    while (current)
    {
        printf("%d: %s - %s\n", current->item.id, current->item.title, current->item.author);
        current = current->next;
    }

    current = head;

    while (current != NULL)
    {
        free(current);
        current = current->next;
    }

    return 0;
}

char * sgets(char * str, int len)
{
	char * temp;
	
	fgets(str, len, stdin);
	
	temp = strchr(str, '\n');
	
	if (temp)
		*temp = '\0';
	else
		while (getchar() != '\n')
			continue;
	
	return str;
}