#include <iostream>
using namespace std ;
int wn, mvs, wmp[4], s, b[10][10] ;
int main() {
   cin >> s ;
   while (wn < 4) {
      s += 15 + s / 13 ;
      if (b[s/10%10][s%10]++ == 0)
         wmp[wn++] = s % 100 ;
   }
   for (mvs=1; ; mvs++) {
      int loc ;
      cin >> loc ;
      if (b[loc/10][loc%10]) {
         b[loc/10][loc%10] = 0 ;
         cout << "You hit a wumpus!" << endl ;
         wn-- ;
      }
      if (wn == 0)
         break ;
      int low = 999 ;
      for (int i=0; i<4; i++)
         if (b[wmp[i]/10][wmp[i]%10])
            low = min(low, abs(wmp[i]/10-loc/10)+abs(wmp[i]%10-loc%10)) ;
      cout << low << endl ;
   }
   cout << "Your score is " << mvs << " moves." << endl ;
}
