/* Author: Peter Schaeffer */
#include <stdio.h>

FILE *in;
int i, n, u[10000], res;

int main()
{
	in=stdin;//fopen("generate.in", "r");
	while(1)
	{
		fscanf(in, " %d", &n);
		if (!n) break;
		res=0;
		for(i=0; i<10000; i++) u[i]=0;
		while(!u[n])
		{
			res++;
			u[n]=1;
			n=((n*n)/100)%10000;
		}
		printf("%d\n", res);
	}
	return 0;
}
