// Author: Walter Guttmann
#include <fstream>
#include <iostream>

using namespace std;

//ifstream in("generate.in");
#define in cin

bool used[1<<14];

int main() {
  int a0;
  while (in >> a0) {
    if (a0 == 0) break;
    for (int i=0 ; i<10000 ; i++)
      used[i] = false;
    int cnt = 0;
    while (!used[a0]) {
      used[a0] = true;
      a0 = ((a0*a0) % 1000000) / 100;
      ++cnt;
    }
    cout << cnt << endl;
  }
  return 0;
}

