import sys input = sys.stdin.readline N=int(input()) U=[input().strip() for i in range(N)] #X="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" #D={X[i]:i for i in range(len(X))} #V=[] #for u in U: # a=[D[u[i]] for i in range(3)] # V.append(a) LEN=N*2 if N>52: print("Impossible") exit() EDGE=[[] for i in range(LEN)] EDGE_INV=[[] for i in range(LEN)] # 0~N : X_i # N+1~2N: Y_i = ¬X_i for i in range(N): a=U[i][:2] b=U[i][2] c=U[i][0] d=U[i][1:] for j in range(i+1,N): e=U[j][:2] f=U[j][2] g=U[j][0] h=U[j][1:] if a==e or b==f: EDGE[i].append(N+j) EDGE[j].append(N+i) EDGE_INV[N+j].append(i) EDGE_INV[N+i].append(j) if a==h or b==g: EDGE[i].append(j) EDGE[N+j].append(N+i) EDGE_INV[j].append(i) EDGE_INV[N+i].append(N+j) if c==f or d==e: EDGE[N+i].append(N+j) EDGE[j].append(i) EDGE_INV[N+j].append(N+i) EDGE_INV[i].append(j) if c==g or d==h: EDGE[N+i].append(j) EDGE[N+j].append(i) EDGE_INV[j].append(N+i) EDGE_INV[i].append(N+j) QUE = list(range(2*N)) check=[0]*(2*N) TOP_SORT=[] def dfs(x): if check[x]==1: return check[x]=1 for to in EDGE[x]: if check[to]==0: dfs(to) TOP_SORT.append(x) # 全ての点からDFSを行い, 帰りがけに点を答えに入れる check[x]=1 while QUE: x=QUE.pop() dfs(x) USE=[0]*(2*N) SCC=[] def dfs2(x): Q=[x] USE[x]=1 ANS=[] while Q: x=Q.pop() ANS.append(x) for to in EDGE_INV[x]: if USE[to]==0: USE[to]=1 Q.append(to) return ANS for x in TOP_SORT[::-1]: if USE[x]==0: SCC.append(dfs2(x)) PLACE=[-1]*(2*N) for i in range(len(SCC)): for x in SCC[i]: PLACE[x]=i ANS=[-1]*N flag=1 for i in range(N): if PLACE[i]==PLACE[N+i]: flag=0 break elif PLACE[i]>PLACE[N+i]: ANS[i]=U[i][:2],U[i][2] else: ANS[i]=U[i][0],U[i][1:] if flag==0: print("Impossible") else: for ans in ANS: print(*ans)