#!/bin/python3

s = int(input())

def rng():
    global s
    s = s + s//13 + 15
    return s%100

def get_wump():
    w = rng()
    return (w//10, w%10)

def dist(a, b): return abs(a[0]-b[0]) + abs(a[1] - b[1])

wump = set()
while len(wump) < 4: wump.add(get_wump())

moves = 0
while wump:
    bonk = tuple(map(int, input()))
    if bonk in wump:
        print("You hit a wumpus!")
        wump.remove(bonk)

    if wump: print(min(dist(bonk, w) for w in wump))
    moves += 1

print("Your score is", moves, "moves.")
