#include<iostream>
using namespace std;
int main()
{
int n,c=0;
while(cin>>n&&n!=0)
{
c++;
int y[20],a[20],b[20],ans;
bool match=false;
for(int i=0;i<n;i++)
cin>>y[i]>>a[i]>>b[i];
ans=y[0];
while(ans<10000)
{
bool t=true;
for(int i=1;i<n;i++)
{
int k=ans,d=b[i]-a[i];
if(k>=b[i])
k=(k-b[i])%d+a[i];
if(k!=y[i])
{
t=false;
break;
}
}
if(t)
{
match=true;
break;
}
ans+=(b[0]-a[0]);
}
cout<<"Case #"<<c<<":\n";
if(match)
cout<<"The actual year is "<<ans<<".\n\n";
else
cout<<"Unknown bugs detected.\n\n";
}
return 0;
}