Under construction

Still being built. Things may change

Acowdemia II

Interview

Time limit1sMemory limit512 MB

Summary
Given K author lists ordered by effort, determine for each pair of N lab members whether one is definitely more senior, using alphabetical tie-breaks.
Level

Medium5 of 10

Topics
Graph, Topological sort
Solved
No attempts yet

Problem

Bessie is applying to computer science graduate school and has secured an interview at a prestigious computer science lab. To avoid offending anyone, Bessie wants to determine the relative seniority of the NN current members of the lab (1≤N≤1001 \leq N \leq 100). No two members have the same seniority, but determining seniority may be tricky. Bessie will look at the lab's publications.

Each publication has an author list, which is an ordering of all NN lab members. The list is in decreasing order of the effort each member contributed to the paper. If several researchers put in equivalent effort, they are ordered alphabetically. More senior members have more administrative duties, so a more senior researcher never puts in more effort than a more junior researcher.

For example, in a lab with a junior student Elsie, a more senior Prof. Mildred, and a very senior Prof. Dean, there may be a paper (Elsie-Mildred-Dean) if all three put in different amounts of effort (Elsie more than Mildred, and Mildred more than Dean). There may also be a paper in the order (Elsie-Dean-Mildred) if Mildred and Dean put in the same effort and Elsie put in more.

Input

The first line contains two integers KK and NN (1≤K≤1001 \leq K \leq 100).

The second line contains NN space-separated names of the lab members. Each name consists of lowercase letters and is at most 10 characters long.

Each of the next KK lines contains NN space-separated names, the author list for one publication.

Output

Print NN lines with NN characters each. On line ii, for any j≠ij \neq i, character jj is 11 if member ii is definitely more senior than member jj, 00 if member ii is definitely more junior than member jj, and ? if it is impossible to tell from the given publications. Character ii on line ii is B, Bessie's favorite letter.

Examples2

  1. Example 1

    Input
    1 3
    dean elsie mildred
    elsie mildred dean
    
    Expected output
    B11
    0B?
    0?B
    
  2. Example 2

    Input
    2 3
    elsie mildred dean
    elsie mildred dean
    elsie dean mildred
    
    Expected output
    B00
    1B0
    11B