4
39 20
183 11
551 27
85 16 8
4 65
5 12
7 24
9 38
12 24
14 10
65 75
31 26
Case 1: 9
Case 2: 4
Case 3: 6
Case 4: 11
 Case 1: 8
Case 2: 3
Case 3: 4
Case 4: 9
Case 5: 5
Case 6: 7
Case 7: 6
Case 8: 9

import math
t=int(raw_input())
i=1
while(t):
	a,b=map(int,raw_input().split())
	s=""
	k=len(str(b))
	n=1
	count=0
	while(str(b)!=s):
		y=n*math.log(a,10)
		m=y-int(y)
		s=str(pow(10,m)*pow(10,k-1))[0:k]
		
		count+=1
		n+=1
	
	print "Case %d:"%i,count
	i+=1
	t-=1