This page is still under construction.

Parts of this page are still being built. What you see may change.

A Game Called Mind

Interview

Time limit1sMemory limit1024 MB

Summary
Given each player's sorted cards, print the player letter for every card in ascending order of card value.
Level

Easy2 of 10

Topics
Sorting, Array
Solved
No attempts yet

Problem

This problem deals with a simplified version of a game called "Mind". In this game, a group works together to solve a problem. Assume:

  • There are 2 to 6 players (called A, B, C, D, E, F).
  • Each player has 1 to 9 cards in sorted order.
  • Each card value is between 10 and 99 (inclusive).
  • There are no duplicate values. A card (number) is in at most one hand.

The goal is for all the players to put all the cards down in sorted order. In the real game, players cannot see their own cards, which is where the name Mind comes from. Given the cards in each hand, you must provide the order in which the players place their cards down.

Input

The first line contains an integer pp (2≤p≤62 \le p \le 6), the number of players. Each of the following pp lines gives the cards for one player. Each line starts with an integer cc (1≤c≤91 \le c \le 9), the number of cards for that player, followed by the cc cards in sorted order. Each card is an integer between 10 and 99, inclusive.

Output

Print the order in which the players place down the cards so that all the cards end up in sorted order.

Examples2

  1. Example 1

    Input
    2
    3 10 40 50
    2 20 30
    
    Expected output
    ABBAA
    
  2. Example 2

    Input
    3
    4 40 51 60 70
    3 12 32 42
    5 20 53 80 90 95
    
    Expected output
    BCBABACAACCC