p1 = [int(x) for x in input().split(" ")]
n, m, t = p1[0], p1[1], p1[2]

for i in range(m):
    train = [(int(x) if i != 2 else x) for i, x in enumerate(input().split(" "))]
    p, s, d, l = train

    head = p + (s*t + l - 1 if d == "R" else -s*t)
    tail = p + (s*t if d == "R" else -s*t + l-1)

    left = min(head, tail)
    right = max(head, tail)
    track = []

    for j in range(n):
        if (j == head):
            track.append("!")
        elif (j >= left and j <= right):
            track.append("#")
        else:
            track.append("=")
    
    print("".join(track))