import sys
from __future__ import print_function

import MEGA

if len(sys.argv)!=2:
    print("python %s chro" % (sys.argv[0]))
    sys.exit(-1)

chro = sys.argv[1]

toks = sys.stdin.readline().rstrip().split("\t")
inds_chro = toks[2:]
inds = []
for ic in inds_chro:
    if ic.endswith("A"):
        inds.append(ic[:-2])

rsids = {}
rsOrder = []
for l in sys.stdin:
    toks = l.rstrip().split("\t")
    pos = int(toks[1])
    alist = toks[2:]
    alleles = list(set(alist))
    if len(alleles)==1:
        if alleles[0] == "G": #just append something different
            alleles.append("T")
        else:
            alleles.append("G")
    for i in range(len(alist)):
        alist[i] = alleles.index(alist[i])
    rsOrder.append(toks[0])
    rsids[toks[0]] = pos, alleles, alist

for rs in rsOrder:
    pos, alleles, alist = rsids[rs]
    print(chro, rs, pos, alleles[0], alleles[1], end=' ')
    for a in alist:
        print(a, end=' ')
    print()

print("ID_1 ID_2 missing", file=sys.stderr)
print("0    0    0", file=sys.stderr)
for ind in inds:
    print(ind, ind, "0", file=sys.stderr)
