/*
  AOJ 2195
  Title:Cat Number
  @kankichi573
*/
#include <stdio.h>
#include <math.h>
#include <float.h>

int da,db;

int is_square(long long n)
{
  long long a;
  a = (long long)sqrt((double)n);
  return(n == (long long)(a*a));
}
long long expt10(int n)
{
  if(n<=0)
    return(1LL);
  else
    return (expt10(n-1)*10LL);
}

void solve(int da,int db)
{
  long long start_b,end_b,start_a,end_a,i,b,d;
  int cnt;
  start_a = expt10(da-1);
  end_a   = expt10(da);
  start_b = expt10(db-1);
  end_b   = expt10(db);

  cnt=0;
  for(i=start_a;i<end_a;i++)
    {
      //printf("a=%lld\n",i);
      if(is_square(d=(1+4*(2*i*end_b+i*i-i))))
	{
	  //printf("d=%lld\n",d);
	  if(b=(sqrt(d)+1)/2,b>=start_b && b < end_b)
	    {
	      cnt++;
	      printf("%lld %lld\n",i,b);
	    }
	}
    }
  if(cnt==0)
    printf("No cats.\n");
}


main()
{
  int i,ret;
  long long N;

  while(scanf("%lld",&N)  && (N))
    {
      for(i=0;i<N;i++)
	{
	  scanf("%d %d",&da,&db);
	  solve(da,db);
	}
    }

  return(0);
}