include <stdio.h>
int main(){
int lenth,number,i;
scanf("%d%d",&lenth,&number);
int array[num];
for(i=0;i<=number;i++){
    int n;
    scanf("%d",n);
    array[i]=n;
}//����һ�����鴢�����е���
int j,m,temp;
for (j=0;j<=num;j++){
    for(m=j;m<=num;m++){
        if(array[m]>array[m+1]){
            temp=arrar[m];
            array[m]=array[m+1];
            array[m+1]=temp;
        }
    }
}//�����е�����������Ȼ��������д��������
double r,minius;
for(i=0;i<=num;i++){
    if((array[i+1]-array[i])-((array[i+2])-array[i+1])<0){
        minius=array[i+2]-array[i+1];
    }
}//�ҳ���������������� ����1/2��Ϊ����
r=minius/2.0;
printf("%10f",r);
return 0;
}


#include<stdio.h>
#include<math.h>
int main()
{
	double a[1000];
	double b[1000];
	double l,max=0;
	int n;
		do
	{
		scanf("%d",&n);
	}while(n<1||n>1000);
	do
	{
		scanf("%lf",&l);
	}while(l<1||l>1E9);
	int i;
	for(i=0;i<n;i++)
	{
	do
	{
	scanf("%lf",a[i]);
}while(a[i]<0||a[i]>l);
}
	for(i=0;i<n-1;i++)
	{
		b[i]=fabs(a[i]-a[i+1]);
	}
	max=b[0];
	for(i=1;i<n;i++)
	{
		if(b[i-1]<b[i])
		{
			max=b[i];
		}
	}
	printf("%lf",max/2.0);
	return 0;
}


#include<stdio.h>
#define N 100
int main()
{
int n,l,max,min;
int a[N];
double d,;
scanf("%d%d",&n,&l);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
max=a[0];
for(i=0;i<n-1;i++)
{
if(a[i+1]>max)
max=a[i+1];
}
min=a[0];
for(i=0;i<n-1;i++)
{
if(a[i+1]<min)
min=a[i+1];
}
d=(max-min)*1.0/2;
printf("%lf",d);
return 0;
}


#include <stdio.h>
long int l;
int n,location;
double d;
int main()
{
scanf("%l%d",&l,&n);
scanf("%d",&location);
if((n-location)>(location-1))
{d=l*(n-location)/(n-1);}
else
{d=l*(location-1)/(n-1);}
printf("%lf",d);
return 0;

}


#include<stdio.h>
int main()
{
	double l,n,d,i;
	scanf("%d%d",&l,&n);
	double j,p=0;
	d=l/((n-1)*2);
	j=0;
	for(i=0;j<l;i++)
	{
		j=j+d;
		printf("%5lf",j);
	}
	printf("%lf",d);
}


#include <stdio.h>
#include<math.h>
int max()
int main()
{
	int a,b,n,i;
	int c[]={0};
	double d;
do
{
scanf("%d%d",&a,&b);
}while((a<1||a>10^9)||(b<1||n>?1000));
for(i=0;i<=b;i++)
	scanf("%d",&c[i]);
do
{
	d=max/2;
	printf("%.1f",d);
}while(d>= 10^(-9));
return 0;
}


#include<stdio.h>
#include<math.h>
#define N 1000
int max(int a[],n)
{
    int i,j,max;
    max=fabs(a[0]-a[1]);
    for(i=1;i<n,i++)
        for(j=2;j<n-i;j++)
            if(max<a[i]-a[j])
                max=a[i]-a[j];
    return 0;
}
int main()
{
    double l,n,d;
    int a[N],i,j;
    do
    {
        scanf("%d %d",&l,&n);
    }while(l<1&&l>10^9&&n<1&&n>1000)
    for(i=0;i<n;i++)
    {
         scanf("%d",&a[i]);
    }
    d=max(a,n)/2
    printf("%f",d);
    return 0;
}


#include<stdio.h>
void pai(int a[],int i)
{
	int m,n,min;
	for(m=0;m<i;m++)
	{
		for(n=m;n<i;n++)
		{
			if(a[n]<a[m])
			{
				min=a[n];
				a[m]=a[n];
				a[n]=a[m];
			}

		}

	}

}
int min(int a[],int i)
{
	int m,minid=a[0];
	for(m=0;m<i;m++)
	{
			if(a[m+1]-a[m]>minid)
				minid=a[m+1]-a[m];
			if(i-a[i-1]>minid)
				minid=i-a[i];
	}
	return minid;
}
int main()
{
	double d;
	int l,n,i,minid;
	int a[1000];
	scanf("%d%d",&l,&n);
	for(i=0;i<1000;i++)
	{
		scanf(" %d",&a[i]);
		if(a[i]==0)
			break;
	}
	min(a,i);
	minid=min(a,i);
	d=1.0*l/3/(n-1)*minid;
	printf("%f",d);

	return 0;
}


#include<stdio.h>
int max(int i,int a[],int n)
{
	int e,c,temp;

	for(e=0;e<n-1;e++)
	{
		if(a[e]<=i)
		{

		for(c=1;c<n;c++)
		{
			if(a[e]<a[c])
			{
				temp=a[e];
				a[e]=a[c];
				a[c]=temp;
			}

		}
	}
	}
	return a[0]-a[1];
}
int main()
{
	int i,n,t;
	int a[100];
	double d;
	scanf("%d%d",&i,&n);
	for(t=0;t<n;t++)
	{
		scanf("%d",&a[t]);
	}
    d=max(i,a,n)/2;
    printf(",8lf",d);
    return 0;
}


#include <stdio.h>
int main()
{
	int l, n, ;
	int i, temp;
	scanf("%d %d", &n, &l);
	int lattern[n];
	for (i=0;i<n;i++)
	{
		scanf("%d", &lattern[i]);
	}

	for(;n>0;n--)
	{
			for(i=0;i<n-1;i++)
			{
				if(lattern[i] > lattern[i+1])
				{
					temp=lattern[i];
			        lattern[i]=lattern[i+1];
			        lattern[i+1]=temp;
				}
				else
				;
		    }
	}

	double dif[n+1];
	dif[0]=(lattern[0]-0)/2.0;
	dif[n+1]=(l-lattern[n])/2.0;
	for(i=1;i<n;i++)
	{
		dif[i]=(lattern[i+1]-lattern[i])/2.0;
	}
    for(;n>0;n--)
	{
			for(i=0;i<=n;i++)
			{
				if(dif[i]>dif[i+1])
				{
					temp=dif[i];
			        dif[i]=dif[i+1];
			        dif[i+1]=temp;
				}
				else
				;
		    }
	}
    printf("%lf",dif[n+1]/2.0);
	return 0;
}


#include<iostream>
#include<cstdlib>
#include<stdio.h>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
long long I,n,a[1005];
int main()
{  int i;
    cin>>I>>n;
    for( i=1;i<=n;i++)
    cin>>a[i];
    a[n+1]=I;
    a[0]=0;
    sort(a,a+i+1);
    double d;
     for( i=0;i<=n;i++)
     { if(a[i+1]-a[i]>d)
       d=a[i+1]-a[i];
	 }
	 printf("%.10f",d/2);

    return 0;
}


#include<stdio.h>
#include<math.h>
int main()
{
int i,m,n;
double d,x;
scanf("%d%d",&m,&n);
int a[n]={0};
for(i=0;i<n_1,i++)
{
scanf("%d",a[i]);
}
d=fabs(a[0]-a[1])/2;
for(i=0;i<n;i++)
{
x=fabs(a[i]-a[i+1])/2;
if(x>d)
d=x;
printf("%lf");
return 0;
}


#include <stdio.h>
#include <math.h>
int main()
{
int a,b,c,d,e,f;
double c;
int a[200];
int b[200];
scanf("%d%d",&a,&b��;
putchar('\n');

for(i=1;i<=b;i++)
{
scanf("%d",&a[i]);
b[i]=a[i]-a[i-1];
}
d=max(b);  //���b������������
c=1.0*a/b;
e=d*c;   //ľͰ���ۣ��Ƶ������뾶ȡ������Զλ���ϵ�������
printf("%d",e);
return 0;
}


#include<stdio.h>
#include<math.h>
int main(){
	int l,n,i=0;
	int flag=1;
	int temp;
	int j,k;
	double max=0;
	double x;
	int pos[1000]={0};
	scanf("%d%d",&l,&n);
	getchar();
	do {
		scanf("%d",&pos[i]);
		getchar();
		i++;
	}while(getchar()=='\n');
	for(i=0;i<n;i++){
		for(j=n;j>=i;j--){
			if(pos[j]>pos[j+1]){
				temp=pos[j+1];
				pos[j+1]=pos[j];
				pos[j]=temp;
			}
		}
	}
	for(k=0;k<n;k++){
		if(x=fabs(pos[k+1]-pos[k])>max)
			max=x;
	}
	printf("%f",max/2);
	getchar();
	return 0;
}


#include <cstdio>
#include <iostream>

using namespace std;
 int main()
 {
 double n,l,d,a[n],max=0,min=0,temp1,temp2,temp3=0,res;
 cin>>n>>l;
 for(int i=0;i<n;i++)
  {cin>>a[i];
	if (a[i]>=max)
     max=a[i];
	if( a[i]<=min)
	 min=a[i];
  }
  temp1=l-max;
  temp2=min;
  for(int j=0;j<n;j++)
    {
	if((a[j+1]-a[j])>temp3)
	temp3=a[j+1]-a[j];

	}
d=temp1;
  if(temp2>d)
  d=temp2;
  if(temp3>d)
  d=temp3;

  res=d;

  cout<<res;

  return 0;

 }


#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int a[1005];
int main()
{
	int l,n;
	cin>>n>>l;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	sort(a,a+n);
	double max1=0;
	double j,m;
	for(int i=0;i<n;i++)
	{
		j=(a[i+1]-a[i])/2.0;
		max1=max1>j?max1:j;
	}
	printf("%f\n",max1);
	return 0;
}


#include<stdio.h>
#include<math.h>
int main()
{
int n,i,max,min;
int a[1000];
double l,d;
do
scanf("%lf%d",&l,&n);
while(l<1||l>pow(10,9)||n<1||n>1000);
for(i=0;i<n;i++)
{
scanf("%d",a[i]);
}
for(i=0;i<n;i++)
{min=a[i];
for(i=0;i<n-1;i++)
{if(a[i+1]<min)
min=a[i];
}
}
for(i=0;i<n;i++)
{max=a[i];
for(i=0;i<n-1;i++)
{if(a[i+1]>max)
max=a[i];
}
}
d=(max-min)/2.0
printf("%f",d);
return 0;
}


#include <stdio.h>
#define N 100

int main()
{
	int l,n,a[N],max=0;
	scanf("%d %d",&n,&l);
	for (int i=0;i<n;i++) scanf("%d",&a[i]);
	for (int i=0;i<n;i++){
		for (int j=0;j<n-i-1;j++) {if (a[j]>a[j+1]) {int temp=a[j];a[j]=a[j+1];a[j+1]=temp;}}
	}
	for (int i=0;i<n-1;i++) {
		if (a[i+1]-a[i]>max) max=a[i+1]-a[i];
	}

	printf ("%.10f",max/2.0);
    return 0;
}


#include <stdio.h>
void paixu(int array);
#define n
int main()
{
	int l;
	scanf("%d%d",&l,&n);
	int array[n],b[n],i;
	double d;
	for(i=0;i<n;i++)
		scanf("%d"'&array[i]);
	paixu(array);
	for(i=1;i<n-2)
		b[i]=array[i+1]-array[i];
	b[n-1]=l-arrey[n];
	b[0]=array[0];
	paixu(b);
	d=b[0]/2.0;
	printf("%12lf",d);
	return 0;
}

void paixu(int array)
{
	int t,i,k;
	for(k=n;k>=0;k--)
	{
		for(i=k;i>0;i--)
		{
			if(array[i]<array[i-1])
			{
				t=array[i];
				array[i]=array[i-1];
				array[i-1]=t;
			}
		}
	}
	return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
int main(void)
{
    int l,n,x,y;
    scanf("%d%d",&l,&n);
	int a[1005]={0},b[1005]={0};
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
     sort(a+1,a+n+1);
     for(int i=1;i<=n;i++)
     {
     	b[i]=a[i]-a[i-1];
	 }
	 double max=11-a[n];
     for(int i=1;i<=n;i++)
     {
     	if(max<b[i]) max=b[i];

	 }
	 if(max==a[1]-0 && a[1]!=0)
	  printf("%.10f",max);
	  else
	 printf("%.10f",max/2);
	 return 0;
}


#include <stdio.h>
#include <stdlib.h>
int main()
{
	double l,d;
	int n,i,temp,difference;
	int a[1000],b[1000];
	scanf("%lf %d",&l,&n);
	if(l>=1&&l<=1E9&&n>=1&&n<=1000)
	{
	   for(i = 0;i<=n-1;i++)
	   {
		  scanf("%d ",a[i-1]);
		  if(a[i+1]<a[i])
		  {
			  temp = a[i+1];
			  a[i+1] = a[i];
			  a[i] = temp;
		  }
		  b[i] = a[i+1]-a[i];
		  if(b[i+1]>b[i])
		  {
			  difference = b[i];
		  }
	   }
	}
    d = difference / 2.0;
	printf("%.9lf",d);
	system("pause");
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n;
double ans=0,l;
double a[1001];
int main(){
	scanf("%d%lf",&n,&l);
	for (int i=1;i<=n;i++) scanf("%lf",&a[i]);
	sort(a+1,a+n+1);
	for (int i=2;i<=n;i++) ans=max(a[i]-a[i-1],ans);
	ans=max(ans/2,max(a[1],l-a[n]));
	printf("%.10lf",ans);
	return 0;
}


#include <set>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <iomanip>
using namespace std;
int main(){
	long long l,n,light[1005];
	scanf("%I64d%I64d",&l,&n);
	for(long long i=1;i<=n;i++)
	    scanf("%I64d",&light[i]);
	sort(light+1,light+n+1);
	long long maxp=-1;
	for(long long i=2;i<=n;i++){
		if(light[i]-light[i-1]>maxp) maxp=light[i]-light[i-1];
	}
	long long lefts=light[1],rights=l-light[n];
	double radiu=max(lefts,rights),ave=double(maxp)/2;
	cout<<setprecision(10)<<max(radiu,ave)<<endl;
	return 0;
}


#include<stdio.h>
int main()
{
int n;
double l,d;
do
{
scanf("%lf",&l);
}while(l>=1&&l<=10^9);
do
{
scanf("%d",&n);
}while(n>=1&&n<=1000);
d=l/(2(n-1));
printf("%f\n",d);
return 0;
}


#include <iostream>

#include <stdio.h>
using namespace std;

int main()
 {
	double longg,d;
	int num,i,ii;
	int set[1000]={0};
	double mark;
	cin>>num>>longg;

	for (i=0;i<num;i++)
	{
		cin>>set[i];
	}
	for (i=0;i<num-1;i++)
	{
		for (ii=num-1;ii>i;ii--)
		{
			if (set[ii]>set[ii-1])
			{

			mark=set[ii];
			set[ii]=set[ii-1];
			set[ii-1]=mark;
			}
		}
	}
	mark=0;
	for (i=0;i<num;i++)
	{
		if(mark<set[i]-set[i+1])
		mark=set[i]-set[i+1];
	}
	d=mark/2;
	cout<<d;
	return 0;
}


#include <stdio.h>
#include <math.h>
double position[100]={0};
double table[100]={0};

int main()
{
	int n,i,j,panduan,m;
	double l,q=0,p;
	scanf("%d",&n);
	scanf("%lf",&l);
	for(i=1;i<=n;i++)
		scanf("%lf",&position[i]);
	for(m=1;m<=n;m++)
	{
		panduan=1;
		for(i=1;i<=n;i++)
		{
			for(j=1;j<=n;j++)
			{
				if(position[i]>position[j])
					panduan=0;
			}
			if(panduan==1)
			{
				table[m]=position[i];
				position[i]=l+1;
				panduan=0;
			}
		}
	}//�������������е��Ǵ�ģ��ұ�������table���ϴ��position�е���Сֵ
	for(i=1;i<=n-1;i++)
	{
		p=table[i+1]-table[i];
	    if(q<p)
			q=p;
	}
	printf("%f",q/2);
	return 0;
}


#include<stdio.h>
int main()
{
  int l,n,d;
  scanf("%d",&l��&n����
  for(1<=l,l<=10^9//1<=n,n<=1000)
  {
    d=l/2*n;
    printf("%d\n",d);
   }
  return 0;
}


#include <stdlib.h>
int main()
{
	double x=0, y, y1,y2,max;
	int l, n, i;
	do{
		scanf("%lf",l);
	}while(1<=l&&l<=1e9);

	do{
		scanf("%d",n);
	}while(1<=n&&n<=1000);

	const int N=n+2;

	int array[N];

	array[0]=0;
	array[N-1]=l;

	for(i=1; i<=N; i++)
	{
		scanf("%d", &array[i]);
	}

	//��array�������С��������

	for(i=1; i<=N-3; i++)
	{
		y=array[i+1]-array[i];
		if(y>x)
		x=y;
	}

	x=x/2;

	y1=array[1]-array[0];
	y2=array[N-1]-array[N-2];

	max=x>=(y1>=y2?y1,y2)?x,(y1>=y2?y1,y2);

	printf("%f",max);
	return 0;
}


#include <iostream>
#include <vector>
#include<iomanip>
using namespace std;
int main ()
{
    long n ;
    double l;
    cin>>n>>l;
    double lm[n];
    for (int c =0; c<n; c++)
    {
        cin>>lm[c];
    }
    for (int c =0; c<n; c++)
    {
        for (int c2 =c+1; c2<n; c2++)
        {
            if (lm[c2]<lm[c])
            {
                double r = lm[c];
                lm[c] = lm[c2];
                lm[c2] = r;
            }
        }
    }
    double ls = lm[0];
    double le = l - lm[n-1];
    if (ls > le)
    {
        ls = ls;
    }
    else
    {
        ls = le;
    }
    double x = 0;
    for (int c =0; c<n-1; c++)
    {
        if (lm[c+1]-lm[c] > x)
        {
            x = lm[c+1]-lm[c];
        }
    }
    if (ls > x/n)
    {
        cout<<fixed<<setprecision(9)<<ls;
    }
    else
    {
        cout<<fixed<<setprecision(9)<<x/2;
    }

    return 0;
}


#include <iostream>
#include<cmath>;
using namespace std;
int main ()
{
    int n ,l;
    cin>>n>>l;
    int la[n];
    for (int c =0; c<n; c++)
    {
        cin>>la[c];
    }
    for (int c =0; c<n; c++)
    {
        for (int c2 =c+1; c2<n; c2++)
        {
            if (la[c2]<la[c])
            {
                int r = la[c2];
                la[c2] = la[c];
                la[c] = r;
            }
        }
    }
    double mx = la[1]-la[0];
    for (int c =1; c<n-1; c++)
    {
        if (la[c+1]-la[c]>mx)
        {
            mx = la[c+1]-la[c];
        }
    }
    int f = la[0];
    int ls = l - la[n-1];
    if (f > ls)
    {
        f = f;
    }
    else
    {
        f = ls;
    }
    if (f > mx/2)
    {
        cout<<f;
    }
    else
    {
        cout<<mx/2;
    }
    return 0;
}


#include <iostream>
#include<iomanip>
using namespace std;
int main ()
{
    int n ,l;
    cin>>n>>l;
    int lm[n];
    for (int c =0; c<n; c++)
    {
        cin>>lm[c];
    }
    for (int c =0; c<n; c++)
    {
        for (int c2 =c+1; c2<n; c2++)
        {
            if (lm[c2]<lm[c])
            {
                int r = lm[c];
                lm[c] = lm[c2];
                lm[c2] = r;
            }
        }
    }
    int ls = lm[0];
    int le = l - lm[n-1];
    if (ls > le)
    {
        ls = ls;
    }
    else
    {
        ls = le;
    }
    double x = 0;
    for (int c =0; c<n-1; c++)
    {
        if (lm[c+1]-lm[c] > x)
        {
            x = lm[c+1]-lm[c];
        }
    }
    if (ls > x/2)
    {
        cout<<fixed<<setprecision(10)<<ls;
    }
    else
    {
        cout<<fixed<<setprecision(10)<<x/2;
    }

    return 0;
}


#include <iostream>
#include <vector>
#include<iomanip>
using namespace std;
int main ()
{
    long n ,l;
    cin>>n>>l;
    long lm[n];
    for (int c =0; c<n; c++)
    {
        cin>>lm[c];
    }
    for (int c =0; c<n; c++)
    {
        for (int c2 =c+1; c2<n; c2++)
        {
            if (lm[c2]<lm[c])
            {
                long r = lm[c];
                lm[c] = lm[c2];
                lm[c2] = r;
            }
        }
    }
    long ls = lm[0];
    long le = l - lm[n-1];
    if (ls > le)
    {
        ls = ls;
    }
    else
    {
        ls = le;
    }
    double x = 0;
    for (int c =0; c<n-1; c++)
    {
        if (lm[c+1]-lm[c] > x)
        {
            x = lm[c+1]-lm[c];
        }
    }
    if (ls > x/n)
    {
        cout<<ls;
    }
    else
    {
        cout<<fixed<<setprecision(9)<<x/2;
    }

    return 0;
}


#include <iostream>
#include <vector>
#include<iomanip>
using namespace std;
int main ()
{
    long n ,l;
    cin>>n>>l;
    double lm[n];
    for (int c =0; c<n; c++)
    {
        cin>>lm[c];
    }
    for (int c =0; c<n; c++)
    {
        for (int c2 =c+1; c2<n; c2++)
        {
            if (lm[c2]<lm[c])
            {
                double r = lm[c];
                lm[c] = lm[c2];
                lm[c2] = r;
            }
        }
    }
    double ls = lm[0];
    double le = l - lm[n-1];
    if (ls > le)
    {
        ls = ls;
    }
    else
    {
        ls = le;
    }
    double x = 0;
    for (int c =0; c<n-1; c++)
    {
        if (lm[c+1]-lm[c] > x)
        {
            x = lm[c+1]-lm[c];
        }
    }
    if (ls > x/n)
    {
        cout<<fixed<<setprecision(9)<<ls;
    }
    else
    {
        cout<<fixed<<setprecision(9)<<x/2;
    }

    return 0;
}


#include <iostream>
#include <vector>
#include<iomanip>
using namespace std;
int main ()
{
    long n ,l;
    cin>>n>>l;
    long lm[n];
    for (int c =0; c<n; c++)
    {
        cin>>lm[c];
    }
    for (int c =0; c<n; c++)
    {
        for (int c2 =c+1; c2<n; c2++)
        {
            if (lm[c2]<lm[c])
            {
                long r = lm[c];
                lm[c] = lm[c2];
                lm[c2] = r;
            }
        }
    }
    long ls = lm[0];
    long le = l - lm[n-1];
    if (ls > le)
    {
        ls = ls;
    }
    else
    {
        ls = le;
    }
    double x = 0;
    for (int c =0; c<n-1; c++)
    {
        if (lm[c+1]-lm[c] > x)
        {
            x = lm[c+1]-lm[c];
        }
    }
    if (ls > x/n)
    {
        cout<<fixed<<setprecision(9)<<ls;
    }
    else
    {
        cout<<fixed<<setprecision(9)<<x/2;
    }

    return 0;
}


#include <iostream>
#include<iomanip>;
using namespace std;
int main ()
{
    int n ,l;
    cin>>n>>l;
    int la[n];
    for (int c =0; c<n; c++)
    {
        cin>>la[c];
    }
    for (int c =0; c<n; c++)
    {
        for (int c2 =c+1; c2<n; c2++)
        {
            if (la[c2]<la[c])
            {
                int r = la[c2];
                la[c2] = la[c];
                la[c] = r;
            }
        }
    }
    double mx = la[1]-la[0];
    for (int c =1; c<n-1; c++)
    {
        if (la[c+1]-la[c]>mx)
        {
            mx = la[c+1]-la[c];
        }
    }
    double f = la[0];
    int ls = l - la[n-1];
    if (f > ls)
    {
        f = f;
    }
    else
    {
        f = ls;
    }
    if (f > mx/2)
    {
        cout<<fixed<<setprecision(10)<<f;
    }
    else
    {
        cout<<fixed<<setprecision(10)<<mx/2;
    }
    return 0;
}


#include <iostream>
#include <vector>
using namespace std;
int main ()
{
    int n ,l;
    cin>>n>>l;
    int lm[n];
    for (int c =0; c<n; c++)
    {
        cin>>lm[c];
    }
    for (int c =0; c<n; c++)
    {
        for (int c2 =c+1; c2<n; c2++)
        {
            if (lm[c2]<lm[c])
            {
                int r = lm[c];
                lm[c] = lm[c2];
                lm[c2] = r;
            }
        }
    }
    int ls = lm[0] - 0;
    int le = l - lm[n-1];
    if (ls > le)
    {
        ls = ls;
    }
    else
    {
        ls = le;
    }
    float x = 0;
    for (int c =0; c<n-1; c++)
    {
        if (lm[c+1]-lm[c] > x)
        {
            x = lm[c+1]-lm[c];
        }
    }
    if (ls > x/n)
    {
        cout<<ls;
    }
    else
    {
        cout<<x/2;
    }

    return 0;
}


#include <iostream>
#include <vector>
#include<iomanip>
using namespace std;
int main ()
{
    long n ,l;
    cin>>n>>l;
    long lm[n];
    for (int c =0; c<n; c++)
    {
        cin>>lm[c];
    }
    for (int c =0; c<n; c++)
    {
        for (int c2 =c+1; c2<n; c2++)
        {
            if (lm[c2]<lm[c])
            {
                long r = lm[c];
                lm[c] = lm[c2];
                lm[c2] = r;
            }
        }
    }
    double ls = lm[0];
    double le = l - lm[n-1];
    if (ls > le)
    {
        ls = ls;
    }
    else
    {
        ls = le;
    }
    double x = 0;
    for (int c =0; c<n-1; c++)
    {
        if (lm[c+1]-lm[c] > x)
        {
            x = lm[c+1]-lm[c];
        }
    }
    if (ls > x/n)
    {
        cout<<fixed<<setprecision(9)<<ls;
    }
    else
    {
        cout<<fixed<<setprecision(9)<<x/2;
    }

    return 0;
}


#include <iostream>
#include<iomanip>;
using namespace std;
int main ()
{
    int n ,l;
    cin>>n>>l;
    int la[n];
    for (int c =0; c<n; c++)
    {
        cin>>la[c];
    }
    for (int c =0; c<n; c++)
    {
        for (int c2 =c+1; c2<n; c2++)
        {
            if (la[c2]<la[c])
            {
                int r = la[c2];
                la[c2] = la[c];
                la[c] = r;
            }
        }
    }
    double mx = 0;
    for (int c =0; c<n-1; c++)
    {
        if (la[c+1]-la[c]>mx)
        {
            mx = la[c+1]-la[c];
        }
    }
    double f = la[0];
    int ls = l - la[n-1];
    if (f > ls)
    {
        f = f;
    }
    else
    {
        f = ls;
    }
    if (f > mx/2)
    {
        cout<<fixed<<setprecision(10)<<f;
    }
    else
    {
        cout<<fixed<<setprecision(10)<<mx/2;
    }
    return 0;
}


#include <iostream>
#include<iomanip>
using namespace std;
int main ()
{
    int n ,l;
    cin>>n>>l;
    int lm[n];
    for (int c =0; c<n; c++)
    {
        cin>>lm[c];
    }
    for (int c =0; c<n; c++)
    {
        for (int c2 =c+1; c2<n; c2++)
        {
            if (lm[c2]<lm[c])
            {
                int r = lm[c];
                lm[c] = lm[c2];
                lm[c2] = r;
            }
        }
    }
    int ls = lm[0];
    int le = l - lm[n-1];
    if (ls > le)
    {
        ls = ls;
    }
    else
    {
        ls = le;
    }
    double x = 0;
    for (int c =0; c<n-1; c++)
    {
        if (lm[c+1]-lm[c] > x)
        {
            x = lm[c+1]-lm[c];
        }
    }
    if (ls > x/n)
    {
        cout<<fixed<<setprecision(10)<<ls;
    }
    else
    {
        cout<<fixed<<setprecision(10)<<x/2;
    }

    return 0;
}


#include <iostream>
#include <algorithm>
#include <stdlib.h>
#include <math.h>
#include <vector>

using namespace std;

int main()
{
	typedef std::numeric_limits< double > dbl;
	int n, l;
	cin >> n >> l;
	vector <long double> liz(n);
	for (int i = 0; i < n; i++)
		cin >> liz[i];
	sort(liz.begin(), liz.end());
	vector <long double> dist;
	dist.push_back(liz[0] - 0);
	for (int i = 0; i < n - 1; i++) {
		dist.push_back((liz[i + 1] - liz[i]) / 2.0);
	}
	dist.push_back(l - liz[n - 1]);
	long double answer = 0;
	for (int i = 0; i < dist.size(); i++) {
		if (answer < dist[i])
			answer = dist[i];
	}

	cout.precision(dbl::max_digits10);
	cout << answer << endl;
	//system("pause");
}


#include <iostream>
#include <algorithm>
#include <stdlib.h>
#include <math.h>
#include <iomanip>

using namespace std;

int compare (const void * a, const void * b)
{
    return ( *(int*)a - *(int*)b );
}

float distance(long long int a, long long int b){
    return (double)(b-a);
}

int main()
{
    int n;
    long long int l;
    cin>>n>>l;
    long long int *a=new long long int[n+2];
    for(int i=1; i<n+1; i++){
        cin>>a[i];
    }

    qsort(a+1,n,sizeof(long long int),compare);

    a[0]=-a[1];
    a[n+1]=l+distance(a[n],l);

    float distan=distance(a[0],a[1]);
    for(int i=1; i<n; i++){
        if(distance(a[i],a[i+1])/2.0>distan)
            distan=distance(a[i],a[i+1])/2.0;
        cout<<distance(a[i],a[i+1])/2.0<<endl;
        cout<<distan<<endl<<endl;
    }
    if(distance(a[n],a[n+1])>distan)
        distan=distance(a[n],a[n+1]);

    cout<<setprecision(10)<<distan<<endl;
}


#include <bits/stdc++.h>
using namespace std;

long long n, k;

bool check(long long x)
{
	long long res = 0;

	for(int i = 0; i <= k; i++)
	{
		long long x1 = x + i;

		while(x1 > 0)
		{
			res += (x1 % 10);
			x1 /= 10;
		}
	}

	return (res == n);
}

long long make_num(long long sumNums, long long numOfNine, bool haveNine)
{
	if(numOfNine == 0 && haveNine)
	{
		if(sumNums <= 8) return sumNums;
		else return make_num(sumNums - 8, 0, 0) * 10ll + 8;
	}

	if(sumNums < 9)
	{
		return sumNums;
	}

	return make_num(sumNums - 9, max(0ll, numOfNine - 1), haveNine) * 10ll + 9;
}

long long func(long long x)
{
	long long sn = max(0ll, x + k - 9);

	long long res = 2e18;

	for(long long XXX = 0; XXX <= 200; XXX++)
	{
		for(long long y = 0; y <= 20; y++)
		{
			long long fn = min(x + k, 9ll);

			if(XXX - (y * 9) < 0) break;

			if(n ==
			XXX * (k + 1) + (fn * (fn + 1) / 2ll - x * (x + 1) / 2ll + x) + (sn * (sn + 1) / 2ll) - (sn * y * 9ll)
			)
			{
				long long xx = make_num(XXX, y, (y > 0)) * 10ll + x;

				if(xx < res && check(xx))
				res = xx;
			}
		}
	}

	if(res == 2e18) res = -1;

	return res;
}

int main()
{
	int t;
	cin >> t;

	while(t--)
	{
		cin >> n >> k;

		long long res = 2e18;

		for(long long i = 0; i <= 9; i++)
		{
			long long n_res = func(i);
			if(n_res != -1) res = min(res, n_res);
		}

		if(res == 2e18) res = -1;

		cout << res << endl;
	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

long long n, k;

bool check(long long x)
{
	long long res = 0;

	for(int i = 0; i <= k; i++)
	{
		long long x1 = x + i;

		while(x1 > 0)
		{
			res += (x1 % 10);
			x1 /= 10;
		}
	}

	return (res == n);
}

long long make_num(long long sumNums, long long numOfNine, bool haveNine)
{
	if(numOfNine == 0 && haveNine)
	{
		if(sumNums <= 8) return sumNums;
		else return make_num(sumNums - 8, 0, 0) * 10ll + 8;
	}

	if(sumNums < 9)
	{
		return sumNums;
	}

	return make_num(sumNums - 9, max(0ll, numOfNine - 1), haveNine) * 10ll + 9;
}

long long func(long long x)
{
	long long sn = max(0ll, x + k - 9);

	long long res = 2e18;

	for(long long XXX = 0; XXX <= 200; XXX++)
	{
		for(long long y = 0; y <= 20; y++)
		{
			long long fn = min(x + k, 9ll);

			if(XXX - (y * 9) < 0) break;

			if(n ==
			XXX * (k + 1) + (fn * (fn + 1) / 2ll - x * (x + 1) / 2ll + x) + (sn * (sn + 1) / 2ll) - (sn * y * 9ll)
			)
			{
				res = min(res, make_num(XXX, y, (y > 0)) * 10ll + x);
			}
		}
	}

	if(res == 2e18) res = -1;

	return res;
}

int main()
{
	int t;
	cin >> t;

	while(t--)
	{
		cin >> n >> k;

		long long res = 2e18;

		for(long long i = 0; i <= 9; i++)
		{
			long long n_res = func(i);
			if(n_res != -1) res = min(res, n_res);
		}

		if(res == 2e18) res = -1;

		cout << res << endl;
	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

long long n, k;

long long make_num(long long sumNums, long long numOfNine, bool haveNine)
{
	if(numOfNine == 0 && haveNine)
	{
		if(sumNums <= 8) return sumNums;
		else return make_num(sumNums - 8, 0, 0) * 10ll + 8;
	}
	else if(sumNums < 9)
	{
		return sumNums;
	}

	return make_num(sumNums - 9, max(0ll, numOfNine - 1), haveNine) * 10ll + 9;
}

long long func(long long x)
{
	long long sn = max(0ll, x + k - 9);

	long long res = 1e18;

	for(long long XXX = 0; XXX <= 150; XXX++)
	{
		for(long long y = 0; y <= 20; y++)
		{
			long long fn = min(x + k, 9ll);

			if(XXX - (y * 9) < 0) break;

			if(n ==
			XXX * (k + 1) + (fn * (fn + 1) / 2ll - x * (x + 1) / 2ll + x) + (sn * (sn + 1) / 2ll) - (sn * y * 9ll)
			)
			{
				res = min(res, make_num(XXX, y, (y > 0)) * 10ll + x);
			}
		}
	}

	if(res == 1e18) res = -1;

	return res;
}

int main()
{
	int t;
	cin >> t;

	while(t--)
	{
		cin >> n >> k;

		long long res = 1e18;

		for(long long i = 0; i <= 9; i++)
		{
			long long n_res = func(i);
			if(n_res != -1) res = min(res, n_res);
		}

		if(res == 1e18) res = -1;

		cout << res << endl;
	}

	return 0;
}


#include<bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define pb           push_back
#define pii          pair<int,int>
#define vi           vector<int>
#define vvi           vector<vector<int>>
#define vii         vector<pair<int,int>>
#define mp           make_pair
#define FOR(i, n) for (int i = 0; i <  (int)(n); i++)
#define FOR1(i, n) for (int i = 1; i <= (int)(n); i++)
#define FORD0(i, n) for (int i = (int)n; i >= 0; i--)
#define FORD1(i, n) for (int i = (int)n; i >= 1; i--)
#define debug(X) { cout << #X << " = " << (X) << endl; }
#define endl '\n'
#define int long long int
#define TIME (chrono::steady_clock::now().time_since_epoch().count())

using namespace std;
//const int lim = 10000000;
//int ans[151][11];

void solve(){

    /*
    vi sum(lim);
    for(int i = 0; i < lim; i++){
        sum[i] = i % 10 + sum[i/10];
    }
    memset(ans, -1, sizeof ans);
    for(int i = 0; i < lim; i++){
        int tot = 0;
        for(int j = 1; j <= 10; j++){
            tot += sum[i + j -1];
            if(tot > 150)break;
            if(ans[tot][j] == -1){
                ans[tot][j] = i;
            }
        }
    }
    for(int tot = 1; tot <= 150; tot++){
        cout << tot << ": ";
        for(int num = 1; num <= 10; num++){
            cout << ans[tot][num] << " ";
        }
        cout << endl;
    }
    */
    int n,k;cin >> n >> k;
    //f(x+ 1) = f(x) + 1 if not 9 last digit
    //if 9 last digit let x be the longest suffix of 9's then f(x + 1) = 1 + f(x after removing the suffix of 9's)
    int ans = LONG_LONG_MAX;
    for(int lastD = 0; lastD <= 9; lastD++){
        for(int nines = 0; nines <= 16; nines++){
            int digSum = 0;
            if(lastD + k > 9){
                for(int i = lastD; i <= 9; i++)digSum+= i;
                for(int i = 0; i <= (lastD + k) % 10; i++)digSum += i;
                int one = 9 - lastD + 1;
                int other = ((lastD + k) % 10) + 1;
                if(digSum + 9*nines*one + 1*other <= n){
                    int rem = n - (digSum + 9*nines*one + other);
                    if(rem % (k+1) == 0){
                        string pre = "";
                        FOR(i, nines)pre += '9';
                        pre += char('0' + lastD);
                        int each = rem/(k+1);
                        if(each <= 8){
                            pre = to_string(each) + pre;
                            each = 0;
                        }else{
                            pre = to_string(8) + pre;
                            each -= 8;
                        }
                        while(each >= 9){
                            pre = to_string(9) + pre;
                            each -= 9;
                        }
                        if(each)pre = char('0' + each) + pre;
                        ans = min(ans, stoll(pre));
                    }
                }
            }else{
                digSum = ((lastD + (lastD + k))*(k + 1))/2;
                if(digSum <= n){
                    int rem = n - digSum;
                    if(rem % (k+1) == 0){
                        int each = rem/(k+1);
                        string pre = "";
                        while(each >= 9){
                            pre += '9';
                            each -= 9;
                        }
                        if(each)pre = char('0' + each) + pre;
                        pre += char('0' + lastD);
                  //      if(n == 99)debug(pre);
                        ans = min(ans, stoll(pre));
                    }
                }
            }
        }
    }
    if(ans == LONG_MAX){
        cout << -1 << endl;
        return;
    }
    cout << ans << endl;

}

signed main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);

    int t = 1;
    cin >> t;
    FOR(i, t){
        //    cout << "Case #" << i+1 << ": ";
        solve();
    }
}


#include<bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define pb           push_back
#define pii          pair<int,int>
#define vi           vector<int>
#define vvi           vector<vector<int>>
#define vii         vector<pair<int,int>>
#define mp           make_pair
#define FOR(i, n) for (int i = 0; i <  (int)(n); i++)
#define FOR1(i, n) for (int i = 1; i <= (int)(n); i++)
#define FORD0(i, n) for (int i = (int)n; i >= 0; i--)
#define FORD1(i, n) for (int i = (int)n; i >= 1; i--)
#define debug(X) { cout << #X << " = " << (X) << endl; }
#define endl '\n'
#define int long long int
#define TIME (chrono::steady_clock::now().time_since_epoch().count())

using namespace std;
const int lim = 10000000;
int ans[151][11];

void solve(){

    /*
    vi sum(lim);
    for(int i = 0; i < lim; i++){
        sum[i] = i % 10 + sum[i/10];
    }
    memset(ans, -1, sizeof ans);
    for(int i = 0; i < lim; i++){
        int tot = 0;
        for(int j = 1; j <= 10; j++){
            tot += sum[i + j -1];
            if(tot > 150)break;
            if(ans[tot][j] == -1){
                ans[tot][j] = i;
            }
        }
    }
    for(int tot = 1; tot <= 150; tot++){
        cout << tot << ": ";
        for(int num = 1; num <= 10; num++){
            cout << ans[tot][num] << " ";
        }
        cout << endl;
    }
    */
    int n,k;cin >> n >> k;
    //f(x+ 1) = f(x) + 1 if not 9 last digit
    //if 9 last digit let x be the longest suffix of 9's then f(x + 1) = 1 + f(x after removing the suffix of 9's)
    int ans = LONG_MAX;
    for(int lastD = 0; lastD <= 9; lastD++){
        for(int nines = 0; nines <= 16; nines++){
            int digSum = 0;
            if(lastD + k > 9){
                for(int i = lastD; i <= 9; i++)digSum+= i;
                for(int i = 0; i <= (lastD + k) % 10; i++)digSum += i;
                int one = 9 - lastD + 1;
                int other = ((lastD + k) % 10) + 1;
                if(digSum + 9*nines*one + 1*other <= n){
                    int rem = n - (digSum + 9*nines*one + other);
                    if(rem % (k+1) == 0){
                        string pre = "";
                        FOR(i, nines)pre += '9';
                        pre += char('0' + lastD);
                        int each = rem/(k+1);
                        if(each <= 8){
                            pre = to_string(each) + pre;
                            each = 0;
                        }else{
                            pre = to_string(8) + pre;
                            each -= 8;
                        }
                        while(each >= 9){
                            pre = to_string(9) + pre;
                            each -= 9;
                        }
                        if(each)pre = char('0' + each) + pre;
                        ans = min(ans, stoll(pre));
                    }
                }
            }else{
                digSum = ((lastD + (lastD + k))*(k + 1))/2;
                if(digSum <= n){
                    int rem = n - digSum;
                    if(rem % (k+1) == 0){
                        int each = rem/(k+1);
                        string pre = "";
                        while(each >= 9){
                            pre += '9';
                            each -= 9;
                        }
                        if(each)pre = char('0' + each) + pre;
                        pre += char('0' + lastD);
                        ans = min(ans, stoll(pre));
                    }
                }
            }
        }
    }
    if(ans == LONG_MAX){
        cout << -1 << endl;
        return;
    }
    cout << ans << endl;

}

signed main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);

    int t = 1;
    cin >> t;
    FOR(i, t){
        //    cout << "Case #" << i+1 << ": ";
        solve();
    }
}


#include<bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define pb           push_back
#define pii          pair<int,int>
#define vi           vector<int>
#define vvi           vector<vector<int>>
#define vii         vector<pair<int,int>>
#define mp           make_pair
#define FOR(i, n) for (int i = 0; i <  (int)(n); i++)
#define FOR1(i, n) for (int i = 1; i <= (int)(n); i++)
#define FORD0(i, n) for (int i = (int)n; i >= 0; i--)
#define FORD1(i, n) for (int i = (int)n; i >= 1; i--)
#define debug(X) { cout << #X << " = " << (X) << endl; }
#define endl '\n'
#define int long long int
#define TIME (chrono::steady_clock::now().time_since_epoch().count())

using namespace std;
//const int lim = 10000000;
//int ans[151][11];

void solve(){

    /*
    vi sum(lim);
    for(int i = 0; i < lim; i++){
        sum[i] = i % 10 + sum[i/10];
    }
    memset(ans, -1, sizeof ans);
    for(int i = 0; i < lim; i++){
        int tot = 0;
        for(int j = 1; j <= 10; j++){
            tot += sum[i + j -1];
            if(tot > 150)break;
            if(ans[tot][j] == -1){
                ans[tot][j] = i;
            }
        }
    }
    for(int tot = 1; tot <= 150; tot++){
        cout << tot << ": ";
        for(int num = 1; num <= 10; num++){
            cout << ans[tot][num] << " ";
        }
        cout << endl;
    }
    */
    int n,k;cin >> n >> k;
    //f(x+ 1) = f(x) + 1 if not 9 last digit
    //if 9 last digit let x be the longest suffix of 9's then f(x + 1) = 1 + f(x after removing the suffix of 9's)
    int ans = LONG_MAX;
    debug(ans);
    for(int lastD = 0; lastD <= 9; lastD++){
        for(int nines = 0; nines <= 16; nines++){
            int digSum = 0;
            if(lastD + k > 9){
                for(int i = lastD; i <= 9; i++)digSum+= i;
                for(int i = 0; i <= (lastD + k) % 10; i++)digSum += i;
                int one = 9 - lastD + 1;
                int other = ((lastD + k) % 10) + 1;
                if(digSum + 9*nines*one + 1*other <= n){
                    int rem = n - (digSum + 9*nines*one + other);
                    if(rem % (k+1) == 0){
                        string pre = "";
                        FOR(i, nines)pre += '9';
                        pre += char('0' + lastD);
                        int each = rem/(k+1);
                        if(each <= 8){
                            pre = to_string(each) + pre;
                            each = 0;
                        }else{
                            pre = to_string(8) + pre;
                            each -= 8;
                        }
                        while(each >= 9){
                            pre = to_string(9) + pre;
                            each -= 9;
                        }
                        if(each)pre = char('0' + each) + pre;
                        ans = min(ans, stoll(pre));
                    }
                }
            }else{
                digSum = ((lastD + (lastD + k))*(k + 1))/2;
                if(digSum <= n){
                    int rem = n - digSum;
                    if(rem % (k+1) == 0){
                        int each = rem/(k+1);
                        string pre = "";
                        while(each >= 9){
                            pre += '9';
                            each -= 9;
                        }
                        if(each)pre = char('0' + each) + pre;
                        pre += char('0' + lastD);
                        debug(pre);
                        ans = min(ans, stoll(pre));
                    }
                }
            }
        }
    }
    if(ans == LONG_MAX){
        cout << -1 << endl;
        return;
    }
    cout << ans << endl;

}

signed main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);

    int t = 1;
    cin >> t;
    FOR(i, t){
        //    cout << "Case #" << i+1 << ": ";
        solve();
    }
}


#include<bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define pb           push_back
#define pii          pair<int,int>
#define vi           vector<int>
#define vvi           vector<vector<int>>
#define vii         vector<pair<int,int>>
#define mp           make_pair
#define FOR(i, n) for (int i = 0; i <  (int)(n); i++)
#define FOR1(i, n) for (int i = 1; i <= (int)(n); i++)
#define FORD0(i, n) for (int i = (int)n; i >= 0; i--)
#define FORD1(i, n) for (int i = (int)n; i >= 1; i--)
#define debug(X) { cout << #X << " = " << (X) << endl; }
#define endl '\n'
#define int long long int
#define TIME (chrono::steady_clock::now().time_since_epoch().count())

using namespace std;
//const int lim = 10000000;
//int ans[151][11];

void solve(){

    /*
    vi sum(lim);
    for(int i = 0; i < lim; i++){
        sum[i] = i % 10 + sum[i/10];
    }
    memset(ans, -1, sizeof ans);
    for(int i = 0; i < lim; i++){
        int tot = 0;
        for(int j = 1; j <= 10; j++){
            tot += sum[i + j -1];
            if(tot > 150)break;
            if(ans[tot][j] == -1){
                ans[tot][j] = i;
            }
        }
    }
    for(int tot = 1; tot <= 150; tot++){
        cout << tot << ": ";
        for(int num = 1; num <= 10; num++){
            cout << ans[tot][num] << " ";
        }
        cout << endl;
    }
    */
    int n,k;cin >> n >> k;
    //f(x+ 1) = f(x) + 1 if not 9 last digit
    //if 9 last digit let x be the longest suffix of 9's then f(x + 1) = 1 + f(x after removing the suffix of 9's)
    int ans = LONG_MAX;
    for(int lastD = 0; lastD <= 9; lastD++){
        for(int nines = 0; nines <= 16; nines++){
            int digSum = 0;
            if(lastD + k > 9){
                for(int i = lastD; i <= 9; i++)digSum+= i;
                for(int i = 0; i <= (lastD + k) % 10; i++)digSum += i;
                int one = 9 - lastD + 1;
                int other = ((lastD + k) % 10) + 1;
                if(digSum + 9*nines*one + 1*other <= n){
                    int rem = n - (digSum + 9*nines*one + other);
                    if(rem % (k+1) == 0){
                        string pre = "";
                        FOR(i, nines)pre += '9';
                        pre += char('0' + lastD);
                        int each = rem/(k+1);
                        if(each <= 8){
                            pre = to_string(each) + pre;
                            each = 0;
                        }else{
                            pre = to_string(8) + pre;
                            each -= 8;
                        }
                        while(each >= 9){
                            pre = to_string(9) + pre;
                            each -= 9;
                        }
                        if(each)pre = char('0' + each) + pre;
                        ans = min(ans, stoll(pre));
                    }
                }
            }else{
                digSum = ((lastD + (lastD + k))*(k + 1))/2;
                if(digSum <= n){
                    int rem = n - digSum;
                    if(rem % (k+1) == 0){
                        int each = rem/(k+1);
                        string pre = "";
                        while(each >= 9){
                            pre += '9';
                            each -= 9;
                        }
                        if(each)pre = char('0' + each) + pre;
                        pre += char('0' + lastD);
                        ans = min(ans, stoll(pre));
                    }
                }
            }
        }
    }
    if(ans == LONG_MAX){
        cout << -1 << endl;
        return;
    }
    cout << ans << endl;

}

signed main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);

    int t = 1;
    cin >> t;
    FOR(i, t){
        //    cout << "Case #" << i+1 << ": ";
        solve();
    }
}


#include<bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define pb           push_back
#define pii          pair<int,int>
#define vi           vector<int>
#define vvi           vector<vector<int>>
#define vii         vector<pair<int,int>>
#define mp           make_pair
#define FOR(i, n) for (int i = 0; i <  (int)(n); i++)
#define FOR1(i, n) for (int i = 1; i <= (int)(n); i++)
#define FORD0(i, n) for (int i = (int)n; i >= 0; i--)
#define FORD1(i, n) for (int i = (int)n; i >= 1; i--)
#define debug(X) { cout << #X << " = " << (X) << endl; }
#define endl '\n'
#define int long long int
#define TIME (chrono::steady_clock::now().time_since_epoch().count())

using namespace std;
vi adj[(int)5e5];
int visa[(int)5e5];
int visb[(int)5e5];
int a, b;
void dfs(int cur, vector<int>& path){
    path.pb(cur);
    for(int child: adj[cur]){
        dfs(child, path);
    }
    path.pop_back();
    visa[cur]++;
    if(path.size() >= a){
        visa[path[path.size() - a]] += visa[cur];
    }
    visb[cur]++;
    if(path.size() >= b){
        visb[path[path.size() - b]] += visb[cur];
    }
}
void solve(){
    int n;cin >> n;
    cin >> a >> b;
    FOR(i, n)adj[i].clear();
    memset(visa, 0, sizeof visa);
    memset(visb, 0, sizeof visb);
    FOR(i, n-1){
        int par;cin >> par;
        par--;
        adj[par].pb(i + 1);
    }
    vector<int> path;
    dfs(0, path);
    int ans = 0;
    FOR(i, n){
        ans += (visa[i] + visb[i]) * n;
    }
    FOR(i, n){
        ans -= visa[i]*visb[i];
    }
    double val = ans*1.0/(n*n);
    cout << setprecision(10) << val << endl;
}

signed main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);

//    gen();
    int t = 1;
    cin >> t;
    FOR(i, t){
        cout << "Case #" << i+1 << ": ";
        solve();
    }
}


#include<bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define pb           push_back
#define pii          pair<int,int>
#define vi           vector<int>
#define vvi           vector<vector<int>>
#define vii         vector<pair<int,int>>
#define mp           make_pair
#define FOR(i, n) for (int i = 0; i <  (int)(n); i++)
#define FOR1(i, n) for (int i = 1; i <= (int)(n); i++)
#define FORD0(i, n) for (int i = (int)n; i >= 0; i--)
#define FORD1(i, n) for (int i = (int)n; i >= 1; i--)
#define debug(X) { cout << #X << " = " << (X) << endl; }
#define endl '\n'
#define int long long int
#define TIME (chrono::steady_clock::now().time_since_epoch().count())

using namespace std;
//const int lim = 10000000;
//int ans[151][11];

void solve(){

    /*
    vi sum(lim);
    for(int i = 0; i < lim; i++){
        sum[i] = i % 10 + sum[i/10];
    }
    memset(ans, -1, sizeof ans);
    for(int i = 0; i < lim; i++){
        int tot = 0;
        for(int j = 1; j <= 10; j++){
            tot += sum[i + j -1];
            if(tot > 150)break;
            if(ans[tot][j] == -1){
                ans[tot][j] = i;
            }
        }
    }
    for(int tot = 1; tot <= 150; tot++){
        cout << tot << ": ";
        for(int num = 1; num <= 10; num++){
            cout << ans[tot][num] << " ";
        }
        cout << endl;
    }
    */
    int n,k;cin >> n >> k;
    //f(x+ 1) = f(x) + 1 if not 9 last digit
    //if 9 last digit let x be the longest suffix of 9's then f(x + 1) = 1 + f(x after removing the suffix of 9's)
    int ans = LONG_MAX;
    debug(ans);
    for(int lastD = 0; lastD <= 9; lastD++){
        for(int nines = 0; nines <= 16; nines++){
            int digSum = 0;
            if(lastD + k > 9){
                for(int i = lastD; i <= 9; i++)digSum+= i;
                for(int i = 0; i <= (lastD + k) % 10; i++)digSum += i;
                int one = 9 - lastD + 1;
                int other = ((lastD + k) % 10) + 1;
                if(digSum + 9*nines*one + 1*other <= n){
                    int rem = n - (digSum + 9*nines*one + other);
                    if(rem % (k+1) == 0){
                        string pre = "";
                        FOR(i, nines)pre += '9';
                        pre += char('0' + lastD);
                        int each = rem/(k+1);
                        if(each <= 8){
                            pre = to_string(each) + pre;
                            each = 0;
                        }else{
                            pre = to_string(8) + pre;
                            each -= 8;
                        }
                        while(each >= 9){
                            pre = to_string(9) + pre;
                            each -= 9;
                        }
                        if(each)pre = char('0' + each) + pre;
                        ans = min(ans, stoll(pre));
                    }
                }
            }else{
                digSum = ((lastD + (lastD + k))*(k + 1))/2;
                if(digSum <= n){
                    int rem = n - digSum;
                    if(rem % (k+1) == 0){
                        int each = rem/(k+1);
                        string pre = "";
                        while(each >= 9){
                            pre += '9';
                            each -= 9;
                        }
                        if(each)pre = char('0' + each) + pre;
                        pre += char('0' + lastD);
                        if(n == 99)debug(pre);
                        ans = min(ans, stoll(pre));
                    }
                }
            }
        }
    }
    if(ans == LONG_MAX){
        cout << -1 << endl;
        return;
    }
    cout << ans << endl;

}

signed main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);

    int t = 1;
    cin >> t;
    FOR(i, t){
        //    cout << "Case #" << i+1 << ": ";
        solve();
    }
}


#include<bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define pb           push_back
#define pii          pair<int,int>
#define vi           vector<int>
#define vvi           vector<vector<int>>
#define vii         vector<pair<int,int>>
#define mp           make_pair
#define FOR(i, n) for (int i = 0; i <  (int)(n); i++)
#define FOR1(i, n) for (int i = 1; i <= (int)(n); i++)
#define FORD0(i, n) for (int i = (int)n; i >= 0; i--)
#define FORD1(i, n) for (int i = (int)n; i >= 1; i--)
#define debug(X) { cout << #X << " = " << (X) << endl; }
#define endl '\n'
#define int long long int
#define TIME (chrono::steady_clock::now().time_since_epoch().count())

using namespace std;
//const int lim = 10000000;
//int ans[151][11];

void solve(){

    /*
    vi sum(lim);
    for(int i = 0; i < lim; i++){
        sum[i] = i % 10 + sum[i/10];
    }
    memset(ans, -1, sizeof ans);
    for(int i = 0; i < lim; i++){
        int tot = 0;
        for(int j = 1; j <= 10; j++){
            tot += sum[i + j -1];
            if(tot > 150)break;
            if(ans[tot][j] == -1){
                ans[tot][j] = i;
            }
        }
    }
    for(int tot = 1; tot <= 150; tot++){
        cout << tot << ": ";
        for(int num = 1; num <= 10; num++){
            cout << ans[tot][num] << " ";
        }
        cout << endl;
    }
    */
    int n,k;cin >> n >> k;
    //f(x+ 1) = f(x) + 1 if not 9 last digit
    //if 9 last digit let x be the longest suffix of 9's then f(x + 1) = 1 + f(x after removing the suffix of 9's)
    int ans = LONG_LONG_MAX;
    for(int lastD = 0; lastD <= 9; lastD++){
        for(int nines = 0; nines <= 16; nines++){
            int digSum = 0;
            if(lastD + k > 9){
                for(int i = lastD; i <= 9; i++)digSum+= i;
                for(int i = 0; i <= (lastD + k) % 10; i++)digSum += i;
                int one = 9 - lastD + 1;
                int other = ((lastD + k) % 10) + 1;
                if(digSum + 9*nines*one + 1*other <= n){
                    int rem = n - (digSum + 9*nines*one + other);
                    if(rem % (k+1) == 0){
                        string pre = "";
                        FOR(i, nines)pre += '9';
                        pre += char('0' + lastD);
                        int each = rem/(k+1);
                        if(each <= 8){
                            pre = to_string(each) + pre;
                            each = 0;
                        }else{
                            pre = to_string(8) + pre;
                            each -= 8;
                        }
                        while(each >= 9){
                            pre = to_string(9) + pre;
                            each -= 9;
                        }
                        if(each)pre = char('0' + each) + pre;
                        ans = min(ans, stoll(pre));
                    }
                }
            }else{
                digSum = ((lastD + (lastD + k))*(k + 1))/2;
                if(digSum <= n){
                    int rem = n - digSum;
                    if(rem % (k+1) == 0){
                        int each = rem/(k+1);
                        string pre = "";
                        while(each >= 9){
                            pre += '9';
                            each -= 9;
                        }
                        if(each)pre = char('0' + each) + pre;
                        pre += char('0' + lastD);
                  //      if(n == 99)debug(pre);
                        ans = min(ans, stoll(pre));
                    }
                }
            }
        }
    }
    if(ans == LONG_LONG_MAX){
        cout << -1 << endl;
        return;
    }
    cout << ans << endl;

}

signed main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);

    int t = 1;
    cin >> t;
    FOR(i, t){
        //    cout << "Case #" << i+1 << ": ";
        solve();
    }
}


#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define st first
#define nd second
#define pb push_back
#define popb pop_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define sortall(x) sort(all(x));
#define deb(x) cout << #x << " = " << x << endl
#define debv(x) cout << #x << ": "; for (int i = 0; i < (x).size(); i++) cout << (x)[i] << ' '; cout << endl
#define PI 3.1415926535897932384626
#define fastio ios_base::sync_with_stdio(false); cin.tie(); cout.tie(); srand(time(NULL)); cout << fixed << setprecision(1)
typedef pair< int ,int >                pii;
typedef pair< long long, long long >    pll;
typedef vector< pii >                   vii;
typedef vector< pll >                   vll;
typedef long long                       ll;
typedef map< int, int >                 mii;
typedef set< pii >                      sii;
typedef set< int >                      si;
typedef vector< int >                   vi;
typedef vector< ll >                    vl;
typedef long double                     ld;
typedef pair< ld, ld >                  pld;
typedef vector< pld >                   vpld;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
//ordered_set t;
//t.insert(val);
//t.find_by_order(i) - returns iterator to the i-th element in set
//t.order_of_key(i) - index of value i

const ll mod = 1e9 + 7;                 /// 1 000 000 007
const ll mod2 = 119 << 23 | 1;          /// 998244353
const ll mod3 = 467'093'870'598'391;    /// big prime
int inf = 1e9 + 7;
ll INF = 1e14 + 9;

///tagliatelle here
///

ll power (ll x, ll y);
ll inv (ll x);
bool isPrime (ll x);
ll gcd (ll x, ll y);

//================================================================================

const int nax = 2e5 + 13;

void prep(){

}

inline int sum(ll x){
    int res = 0;
    while(x){
        res += (x % 10ll);
        x /= 10ll;
    }
    return res;
}

void solve(){

    int n, k;
    cin >> n >> k;
    if(k > 1){
        if(k==2 && n%3){
            cout << -1 << endl;
            return;
        }
        for(int i = 0; i <= 699997; i++){
            int ans = 0;
            for(int j = 0; j <= k; j++)
                ans += sum(i + j);
            if(ans == n){
                cout << i << '\n';
                return;
            }
        }
        cout << -1 << '\n';
    }else{
        if(k == 0){
            string res;
            while(n >= 9){
                res.pb('9');
                n -= 9;
            }
            if(n > 0){
                res.pb('0' + n);
            }
            reverse(all(res));
            cout << res << '\n';
        }else{
            string res;
            if(n % 2){
                //normal
                n++;
                while(n > 18){
                    res.pb('9');
                    n -= 18;
                }
                if(n > 1)
                    res.pb('0' + (n / 2));
                res[0]--;
                reverse(all(res));
                cout << res << '\n';
            }else{
                //fucked up
                if(n < 10){
                    cout << -1 << '\n';
                    return;
                }else if(n <= 98){
                    for(int i = 9; i <= 1000000; i+=10){
                        if(sum(i) + sum(i+1) == n){
                            cout << i << '\n';
                            return;
                        }
                    }
                }else{
                    for(ll i = 999989ll; i <= 100000000000ll; i += 1000000ll){
                        if(sum(i) + sum(i+1ll) == n){
                            cout << i << '\n';
                            return;
                        }
                    }
                }
            }
        }
    }

}

int main(){            ///use cin and printf if you wanna see some REAL SPEED
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    fastio;
    int T = 1;
    prep();
    cin >> T;
    for(int i = 1; i <= T; i++){
        //cout << "test case " << i << endl;
        solve();
    }
    return 0;
}

ll power (ll x, ll y) {
    ll res = 1ll;
    x %= mod;
    if (x == 0)
        return 0;
    while (y > 0) {
        if (y & 1)
            res = (res * x) % mod;
        y = y >> 1ll;
        x = (x * x) % mod;
    }
    return res;
}

ll inv (ll x) {
    ll r = 1ll, t = x, k = mod - 2ll;
    while (k) {
        if (k & 1ll) r = r * t % mod;
        t = (long long) t * t % mod;
        k >>= 1;
    }
    return r;
}

bool isPrime (ll x) {
    if (x == 1)
        return false;
    for (ll i = 2ll; i * i <= x; i++) {
        if (x % i == 0)
            return false;
    }
    return true;
}

ll gcd (ll x, ll y) {
    if (!y)
        return x;
    return gcd (y, x % y);
}

/*
    __builtin_popcount
    __builtin_ctz
    __builtin_clz
*/


#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define st first
#define nd second
#define pb push_back
#define popb pop_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define sortall(x) sort(all(x));
#define deb(x) cout << #x << " = " << x << endl
#define debv(x) cout << #x << ": "; for (int i = 0; i < (x).size(); i++) cout << (x)[i] << ' '; cout << endl
#define PI 3.1415926535897932384626
#define fastio ios_base::sync_with_stdio(false); cin.tie(); cout.tie(); srand(time(NULL)); cout << fixed << setprecision(1)
typedef pair< int ,int >                pii;
typedef pair< long long, long long >    pll;
typedef vector< pii >                   vii;
typedef vector< pll >                   vll;
typedef long long                       ll;
typedef map< int, int >                 mii;
typedef set< pii >                      sii;
typedef set< int >                      si;
typedef vector< int >                   vi;
typedef vector< ll >                    vl;
typedef long double                     ld;
typedef pair< ld, ld >                  pld;
typedef vector< pld >                   vpld;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
//ordered_set t;
//t.insert(val);
//t.find_by_order(i) - returns iterator to the i-th element in set
//t.order_of_key(i) - index of value i

const ll mod = 1e9 + 7;                 /// 1 000 000 007
const ll mod2 = 119 << 23 | 1;          /// 998244353
const ll mod3 = 467'093'870'598'391;    /// big prime
int inf = 1e9 + 7;
ll INF = 1e14 + 9;

///tagliatelle here
///

ll power (ll x, ll y);
ll inv (ll x);
bool isPrime (ll x);
ll gcd (ll x, ll y);

//================================================================================

const int nax = 2e5 + 13;

void prep(){

}

ll sum(ll x){
    ll res = 0;
    while(x){
        res += (x % 10ll);
        x /= 10ll;
    }
    return res;
}

void solve(){

    int n, k;
    cin >> n >> k;
    if(k > 1){
        for(int i = 0; i < 10000000; i++){
            ll ans = 0;
            for(int j = 0; j <= k; j++)
                ans += sum(i + j);
            if(ans == n){
                cout << i << '\n';
                return;
            }
        }
        cout << -1 << '\n';
    }else{
        if(k == 0){
            string res;
            while(n >= 9){
                res.pb('9');
                n -= 9;
            }
            if(n > 0){
                res.pb('0' + n);
            }
            reverse(all(res));
            cout << res << '\n';
        }else{
            string res;
            if(n % 2){
                //normal
                n++;
                while(n > 18){
                    res.pb('9');
                    n -= 18;
                }
                if(n > 1)
                    res.pb('0' + (n / 2));
                res[0]--;
                reverse(all(res));
                cout << res << '\n';
            }else{
                //fucked up
                if(n < 10){
                    cout << -1 << '\n';
                    return;
                }else if(n <= 26){
                    for(ll i = 0; i <= 10000; i += 100){
                        if(sum(i) + sum(i+1) == n){
                            cout << i << '\n';
                            return;
                        }
                    }
                }else{
                    for(ll i = 89ll; i <= 1000000000ll; i += 100){
                        if(sum(i) + sum(i+1) == n){
                            cout << i << '\n';
                            return;
                        }
                    }
                }
            }
        }
    }

}

int main(){            ///use cin and printf if you wanna see some REAL SPEED
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    fastio;
    int T = 1;
    prep();
    cin >> T;
    for(int i = 1; i <= T; i++){
        //cout << "test case " << i << endl;
        solve();
    }
    return 0;
}

ll power (ll x, ll y) {
    ll res = 1ll;
    x %= mod;
    if (x == 0)
        return 0;
    while (y > 0) {
        if (y & 1)
            res = (res * x) % mod;
        y = y >> 1ll;
        x = (x * x) % mod;
    }
    return res;
}

ll inv (ll x) {
    ll r = 1ll, t = x, k = mod - 2ll;
    while (k) {
        if (k & 1ll) r = r * t % mod;
        t = (long long) t * t % mod;
        k >>= 1;
    }
    return r;
}

bool isPrime (ll x) {
    if (x == 1)
        return false;
    for (ll i = 2ll; i * i <= x; i++) {
        if (x % i == 0)
            return false;
    }
    return true;
}

ll gcd (ll x, ll y) {
    if (!y)
        return x;
    return gcd (y, x % y);
}

/*
    __builtin_popcount
    __builtin_ctz
    __builtin_clz
*/


#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define st first
#define nd second
#define pb push_back
#define popb pop_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define sortall(x) sort(all(x));
#define deb(x) cout << #x << " = " << x << endl
#define debv(x) cout << #x << ": "; for (int i = 0; i < (x).size(); i++) cout << (x)[i] << ' '; cout << endl
#define PI 3.1415926535897932384626
#define fastio ios_base::sync_with_stdio(false); cin.tie(); cout.tie(); srand(time(NULL)); cout << fixed << setprecision(1)
typedef pair< int ,int >                pii;
typedef pair< long long, long long >    pll;
typedef vector< pii >                   vii;
typedef vector< pll >                   vll;
typedef long long                       ll;
typedef map< int, int >                 mii;
typedef set< pii >                      sii;
typedef set< int >                      si;
typedef vector< int >                   vi;
typedef vector< ll >                    vl;
typedef long double                     ld;
typedef pair< ld, ld >                  pld;
typedef vector< pld >                   vpld;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
//ordered_set t;
//t.insert(val);
//t.find_by_order(i) - returns iterator to the i-th element in set
//t.order_of_key(i) - index of value i

const ll mod = 1e9 + 7;                 /// 1 000 000 007
const ll mod2 = 119 << 23 | 1;          /// 998244353
const ll mod3 = 467'093'870'598'391;    /// big prime
int inf = 1e9 + 7;
ll INF = 1e14 + 9;

///tagliatelle here
///

ll power (ll x, ll y);
ll inv (ll x);
bool isPrime (ll x);
ll gcd (ll x, ll y);

//================================================================================

const int nax = 2e5 + 13;

void prep(){

}

ll sum(ll x){
    ll res = 0;
    while(x){
        res += (x % 10ll);
        x /= 10ll;
    }
    return res;
}

void solve(){

    int n, k;
    cin >> n >> k;
    if(k > 1){
        for(int i = 0; i < 1000000; i++){
            ll ans = 0;
            for(int j = 0; j <= k; j++)
                ans += sum(i + j);
            if(ans == n){
                cout << i << '\n';
                return;
            }
        }
        cout << -1 << '\n';
    }else{
        if(k == 0){
            string res;
            while(n >= 9){
                res.pb('9');
                n -= 9;
            }
            if(n > 0){
                res.pb('0' + n);
            }
            reverse(all(res));
            cout << res << '\n';
        }else{
            string res;
            if(n % 2){
                //normal
                n++;
                while(n > 18){
                    res.pb('9');
                    n -= 18;
                }
                if(n > 1)
                    res.pb('0' + (n / 2));
                res[0]--;
                reverse(all(res));
                cout << res << '\n';
            }else{
                //fucked up
                if(n < 10){
                    cout << -1 << '\n';
                    return;
                }else if(n <= 62){
                    for(ll i = 0; i <= 10000; i += 10){
                        if(sum(i) + sum(i+1) == n){
                            cout << i << '\n';
                            return;
                        }
                    }
                }else{
                    for(ll i = 9989ll; i <= 100000000000ll; i += 10000ll){
                        if(sum(i) + sum(i+1) == n){
                            cout << i << '\n';
                            return;
                        }
                    }
                }
            }
        }
    }

}

int main(){            ///use cin and printf if you wanna see some REAL SPEED
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    fastio;
    int T = 1;
    prep();
    cin >> T;
    for(int i = 1; i <= T; i++){
        //cout << "test case " << i << endl;
        solve();
    }
    return 0;
}

ll power (ll x, ll y) {
    ll res = 1ll;
    x %= mod;
    if (x == 0)
        return 0;
    while (y > 0) {
        if (y & 1)
            res = (res * x) % mod;
        y = y >> 1ll;
        x = (x * x) % mod;
    }
    return res;
}

ll inv (ll x) {
    ll r = 1ll, t = x, k = mod - 2ll;
    while (k) {
        if (k & 1ll) r = r * t % mod;
        t = (long long) t * t % mod;
        k >>= 1;
    }
    return r;
}

bool isPrime (ll x) {
    if (x == 1)
        return false;
    for (ll i = 2ll; i * i <= x; i++) {
        if (x % i == 0)
            return false;
    }
    return true;
}

ll gcd (ll x, ll y) {
    if (!y)
        return x;
    return gcd (y, x % y);
}

/*
    __builtin_popcount
    __builtin_ctz
    __builtin_clz
*/


#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define st first
#define nd second
#define pb push_back
#define popb pop_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define sortall(x) sort(all(x));
#define deb(x) cout << #x << " = " << x << endl
#define debv(x) cout << #x << ": "; for (int i = 0; i < (x).size(); i++) cout << (x)[i] << ' '; cout << endl
#define PI 3.1415926535897932384626
#define fastio ios_base::sync_with_stdio(false); cin.tie(); cout.tie(); srand(time(NULL)); cout << fixed << setprecision(1)
typedef pair< int ,int >                pii;
typedef pair< long long, long long >    pll;
typedef vector< pii >                   vii;
typedef vector< pll >                   vll;
typedef long long                       ll;
typedef map< int, int >                 mii;
typedef set< pii >                      sii;
typedef set< int >                      si;
typedef vector< int >                   vi;
typedef vector< ll >                    vl;
typedef long double                     ld;
typedef pair< ld, ld >                  pld;
typedef vector< pld >                   vpld;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
//ordered_set t;
//t.insert(val);
//t.find_by_order(i) - returns iterator to the i-th element in set
//t.order_of_key(i) - index of value i

const ll mod = 1e9 + 7;                 /// 1 000 000 007
const ll mod2 = 119 << 23 | 1;          /// 998244353
const ll mod3 = 467'093'870'598'391;    /// big prime
int inf = 1e9 + 7;
ll INF = 1e14 + 9;

///tagliatelle here
///

ll power (ll x, ll y);
ll inv (ll x);
bool isPrime (ll x);
ll gcd (ll x, ll y);

//================================================================================

const int nax = 2e5 + 13;

void prep(){

}

inline int sum(int x){
    int res = 0;
    while(x){
        res += (x % 10ll);
        x /= 10ll;
    }
    return res;
}

void solve(){
/*
    for(ll i = 9989ll; i <= 1000000000ll; i+=1000ll){
        if((sum(i) + sum(i+1)) %2 == 0){
            cout << i << ' ' << sum(i) + sum(i+1) << endl;
        }
    }
    100000
     99989
    cout << endl;
    return;*/

    int n, k;
    cin >> n >> k;
    if(k > 1){
        for(int i = 0; i < 1000000; i++){
            int ans = 0;
            for(int j = 0; j <= k; j++)
                ans += sum(i + j);
            if(ans == n){
                cout << i << '\n';
                return;
            }
        }
        cout << -1 << '\n';
    }else{
        if(k == 0){
            string res;
            while(n >= 9){
                res.pb('9');
                n -= 9;
            }
            if(n > 0){
                res.pb('0' + n);
            }
            reverse(all(res));
            cout << res << '\n';
        }else{
            string res;
            if(n % 2){
                //normal
                n++;
                while(n > 18){
                    res.pb('9');
                    n -= 18;
                }
                if(n > 1)
                    res.pb('0' + (n / 2));
                res[0]--;
                reverse(all(res));
                cout << res << '\n';
            }else{
                //fucked up
                if(n < 10){
                    cout << -1 << '\n';
                    return;
                }else if(n <= 80){
                    for(int i = 0; i <= 10000; i++){
                        if(sum(i) + sum(i+1) == n){
                            cout << i << '\n';
                            return;
                        }
                    }
                }else{
                    for(ll i = 99989ll; i <= 1000000000ll; i += 100000ll){
                        if(sum(i) + sum(i+1) == n){
                            cout << i << '\n';
                            return;
                        }
                    }
                }
            }
        }
    }

}

int main(){            ///use cin and printf if you wanna see some REAL SPEED
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    fastio;
    int T = 1;
    prep();
    cin >> T;
    for(int i = 1; i <= T; i++){
        //cout << "test case " << i << endl;
        solve();
    }
    return 0;
}

ll power (ll x, ll y) {
    ll res = 1ll;
    x %= mod;
    if (x == 0)
        return 0;
    while (y > 0) {
        if (y & 1)
            res = (res * x) % mod;
        y = y >> 1ll;
        x = (x * x) % mod;
    }
    return res;
}

ll inv (ll x) {
    ll r = 1ll, t = x, k = mod - 2ll;
    while (k) {
        if (k & 1ll) r = r * t % mod;
        t = (long long) t * t % mod;
        k >>= 1;
    }
    return r;
}

bool isPrime (ll x) {
    if (x == 1)
        return false;
    for (ll i = 2ll; i * i <= x; i++) {
        if (x % i == 0)
            return false;
    }
    return true;
}

ll gcd (ll x, ll y) {
    if (!y)
        return x;
    return gcd (y, x % y);
}

/*
    __builtin_popcount
    __builtin_ctz
    __builtin_clz
*/


#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define st first
#define nd second
#define pb push_back
#define popb pop_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define sortall(x) sort(all(x));
#define deb(x) cout << #x << " = " << x << endl
#define debv(x) cout << #x << ": "; for (int i = 0; i < (x).size(); i++) cout << (x)[i] << ' '; cout << endl
#define PI 3.1415926535897932384626
#define fastio ios_base::sync_with_stdio(false); cin.tie(); cout.tie(); srand(time(NULL)); cout << fixed << setprecision(1)
typedef pair< int ,int >                pii;
typedef pair< long long, long long >    pll;
typedef vector< pii >                   vii;
typedef vector< pll >                   vll;
typedef long long                       ll;
typedef map< int, int >                 mii;
typedef set< pii >                      sii;
typedef set< int >                      si;
typedef vector< int >                   vi;
typedef vector< ll >                    vl;
typedef long double                     ld;
typedef pair< ld, ld >                  pld;
typedef vector< pld >                   vpld;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
//ordered_set t;
//t.insert(val);
//t.find_by_order(i) - returns iterator to the i-th element in set
//t.order_of_key(i) - index of value i

const ll mod = 1e9 + 7;                 /// 1 000 000 007
const ll mod2 = 119 << 23 | 1;          /// 998244353
const ll mod3 = 467'093'870'598'391;    /// big prime
int inf = 1e9 + 7;
ll INF = 1e14 + 9;

///tagliatelle here
///

ll power (ll x, ll y);
ll inv (ll x);
bool isPrime (ll x);
ll gcd (ll x, ll y);

//================================================================================

const int nax = 2e5 + 13;

void prep(){

}

ll sum(ll x){
    ll res = 0;
    while(x){
        res += (x % 10ll);
        x /= 10ll;
    }
    return res;
}

void solve(){

    int n, k;
    cin >> n >> k;
    if(k > 1){
        for(int i = 0; i < 1000000; i++){
            ll ans = 0;
            for(int j = 0; j <= k; j++)
                ans += sum(i + j);
            if(ans == n){
                cout << i << '\n';
                return;
            }
        }
        cout << -1 << '\n';
    }else{
        if(k == 0){
            string res;
            while(n >= 9){
                res.pb('9');
                n -= 9;
            }
            if(n > 0){
                res.pb('0' + n);
            }
            reverse(all(res));
            cout << res << '\n';
        }else{
            string res;
            if(n % 2){
                //normal
                n++;
                while(n > 18){
                    res.pb('9');
                    n -= 18;
                }
                if(n > 1)
                    res.pb('0' + (n / 2));
                res[0]--;
                reverse(all(res));
                cout << res << '\n';
            }else{
                //fucked up
                if(n < 10){
                    cout << -1 << '\n';
                    return;
                }else if(n <= 62){
                    for(ll i = 0; i <= 10000; i++){
                        if(sum(i) + sum(i+1) == n){
                            cout << i << '\n';
                            return;
                        }
                    }
                }else{
                    for(ll i = 9989ll; i <= 100000000000ll; i += 1000ll){
                        if(sum(i) + sum(i+1) == n){
                            cout << i << '\n';
                            return;
                        }
                    }
                }
            }
        }
    }

}

int main(){            ///use cin and printf if you wanna see some REAL SPEED
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    fastio;
    int T = 1;
    prep();
    cin >> T;
    for(int i = 1; i <= T; i++){
        //cout << "test case " << i << endl;
        solve();
    }
    return 0;
}

ll power (ll x, ll y) {
    ll res = 1ll;
    x %= mod;
    if (x == 0)
        return 0;
    while (y > 0) {
        if (y & 1)
            res = (res * x) % mod;
        y = y >> 1ll;
        x = (x * x) % mod;
    }
    return res;
}

ll inv (ll x) {
    ll r = 1ll, t = x, k = mod - 2ll;
    while (k) {
        if (k & 1ll) r = r * t % mod;
        t = (long long) t * t % mod;
        k >>= 1;
    }
    return r;
}

bool isPrime (ll x) {
    if (x == 1)
        return false;
    for (ll i = 2ll; i * i <= x; i++) {
        if (x % i == 0)
            return false;
    }
    return true;
}

ll gcd (ll x, ll y) {
    if (!y)
        return x;
    return gcd (y, x % y);
}

/*
    __builtin_popcount
    __builtin_ctz
    __builtin_clz
*/


#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define st first
#define nd second
#define pb push_back
#define popb pop_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define sortall(x) sort(all(x));
#define deb(x) cout << #x << " = " << x << endl
#define debv(x) cout << #x << ": "; for (int i = 0; i < (x).size(); i++) cout << (x)[i] << ' '; cout << endl
#define PI 3.1415926535897932384626
#define fastio ios_base::sync_with_stdio(false); cin.tie(); cout.tie(); srand(time(NULL)); cout << fixed << setprecision(1)
typedef pair< int ,int >                pii;
typedef pair< long long, long long >    pll;
typedef vector< pii >                   vii;
typedef vector< pll >                   vll;
typedef long long                       ll;
typedef map< int, int >                 mii;
typedef set< pii >                      sii;
typedef set< int >                      si;
typedef vector< int >                   vi;
typedef vector< ll >                    vl;
typedef long double                     ld;
typedef pair< ld, ld >                  pld;
typedef vector< pld >                   vpld;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
//ordered_set t;
//t.insert(val);
//t.find_by_order(i) - returns iterator to the i-th element in set
//t.order_of_key(i) - index of value i

const ll mod = 1e9 + 7;                 /// 1 000 000 007
const ll mod2 = 119 << 23 | 1;          /// 998244353
const ll mod3 = 467'093'870'598'391;    /// big prime
int inf = 1e9 + 7;
ll INF = 1e14 + 9;

///tagliatelle here
///

ll power (ll x, ll y);
ll inv (ll x);
bool isPrime (ll x);
ll gcd (ll x, ll y);

//================================================================================

const int nax = 2e5 + 13;

void prep(){

}

inline int sum(ll x){
    int res = 0;
    while(x){
        res += (x % 10ll);
        x /= 10ll;
    }
    return res;
}

void solve(){
/*
    for(ll i = 9989ll; i <= 1000000000ll; i+=1000ll){
        if((sum(i) + sum(i+1)) %2 == 0){
            cout << i << ' ' << sum(i) + sum(i+1) << endl;
        }
    }
    100000
     99989
    cout << endl;
    return;*/

    int n, k;
    cin >> n >> k;
    if(k > 1){
        for(int i = 0; i < 1000000; i++){
            int ans = 0;
            for(int j = 0; j <= k; j++)
                ans += sum(i + j);
            if(ans == n){
                cout << i << '\n';
                return;
            }
        }
        cout << -1 << '\n';
    }else{
        if(k == 0){
            string res;
            while(n >= 9){
                res.pb('9');
                n -= 9;
            }
            if(n > 0){
                res.pb('0' + n);
            }
            reverse(all(res));
            cout << res << '\n';
        }else{
            string res;
            if(n % 2){
                //normal
                n++;
                while(n > 18){
                    res.pb('9');
                    n -= 18;
                }
                if(n > 1)
                    res.pb('0' + (n / 2));
                res[0]--;
                reverse(all(res));
                cout << res << '\n';
            }else{
                //fucked up
                if(n < 10){
                    cout << -1 << '\n';
                    return;
                }else if(n <= 80){
                    for(int i = 9; i <= 100000; i+=10){
                        if(sum(i) + sum(i+1) == n){
                            cout << i << '\n';
                            return;
                        }
                    }
                }else{
                    for(ll i = 99989ll; i <= 100000000000ll; i += 100000ll){
                        if(sum(i) + sum(i+1ll) == n){
                            cout << i << '\n';
                            return;
                        }
                    }
                }
            }
        }
    }

}

int main(){            ///use cin and printf if you wanna see some REAL SPEED
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    fastio;
    int T = 1;
    prep();
    cin >> T;
    for(int i = 1; i <= T; i++){
        //cout << "test case " << i << endl;
        solve();
    }
    return 0;
}

ll power (ll x, ll y) {
    ll res = 1ll;
    x %= mod;
    if (x == 0)
        return 0;
    while (y > 0) {
        if (y & 1)
            res = (res * x) % mod;
        y = y >> 1ll;
        x = (x * x) % mod;
    }
    return res;
}

ll inv (ll x) {
    ll r = 1ll, t = x, k = mod - 2ll;
    while (k) {
        if (k & 1ll) r = r * t % mod;
        t = (long long) t * t % mod;
        k >>= 1;
    }
    return r;
}

bool isPrime (ll x) {
    if (x == 1)
        return false;
    for (ll i = 2ll; i * i <= x; i++) {
        if (x % i == 0)
            return false;
    }
    return true;
}

ll gcd (ll x, ll y) {
    if (!y)
        return x;
    return gcd (y, x % y);
}

/*
    __builtin_popcount
    __builtin_ctz
    __builtin_clz
*/


#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define st first
#define nd second
#define pb push_back
#define popb pop_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define sortall(x) sort(all(x));
#define deb(x) cout << #x << " = " << x << endl
#define debv(x) cout << #x << ": "; for (int i = 0; i < (x).size(); i++) cout << (x)[i] << ' '; cout << endl
#define PI 3.1415926535897932384626
#define fastio ios_base::sync_with_stdio(false); cin.tie(); cout.tie(); srand(time(NULL)); cout << fixed << setprecision(1)
typedef pair< int ,int >                pii;
typedef pair< long long, long long >    pll;
typedef vector< pii >                   vii;
typedef vector< pll >                   vll;
typedef long long                       ll;
typedef map< int, int >                 mii;
typedef set< pii >                      sii;
typedef set< int >                      si;
typedef vector< int >                   vi;
typedef vector< ll >                    vl;
typedef long double                     ld;
typedef pair< ld, ld >                  pld;
typedef vector< pld >                   vpld;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
//ordered_set t;
//t.insert(val);
//t.find_by_order(i) - returns iterator to the i-th element in set
//t.order_of_key(i) - index of value i

const ll mod = 1e9 + 7;                 /// 1 000 000 007
const ll mod2 = 119 << 23 | 1;          /// 998244353
const ll mod3 = 467'093'870'598'391;    /// big prime
int inf = 1e9 + 7;
ll INF = 1e14 + 9;

///tagliatelle here
///

ll power (ll x, ll y);
ll inv (ll x);
bool isPrime (ll x);
ll gcd (ll x, ll y);

//================================================================================

const int nax = 2e5 + 13;

void prep(){

}

ll sum(ll x){
    ll res = 0;
    while(x){
        res += (x % 10ll);
        x /= 10ll;
    }
    return res;
}

void solve(){

    int n, k;
    cin >> n >> k;
    if(k > 1){
        for(int i = 0; i < 10000000; i++){
            ll ans = 0;
            for(int j = 0; j <= k; j++)
                ans += sum(i + j);
            if(ans == n){
                cout << i << '\n';
                return;
            }
        }
        cout << -1 << '\n';
    }else{
        if(k == 0){
            string res;
            while(n >= 9){
                res.pb('9');
                n -= 9;
            }
            if(n > 0){
                res.pb('0' + n);
            }
            reverse(all(res));
            cout << res << '\n';
        }else{
            string res;
            if(n % 2){
                //normal
                n++;
                while(n > 18){
                    res.pb('9');
                    n -= 18;
                }
                if(n > 1)
                    res.pb('0' + (n / 2));
                res[0]--;
                reverse(all(res));
                cout << res << '\n';
            }else{
                //fucked up
                if(n < 10){
                    cout << -1 << '\n';
                    return;
                }else if(n <= 62){
                    for(ll i = 0; i <= 10000; i += 10){
                        if(sum(i) + sum(i+1) == n){
                            cout << i << '\n';
                            return;
                        }
                    }
                }else{
                    for(ll i = 9989ll; i <= 100000000000ll; i += 10000ll){
                        if(sum(i) + sum(i+1) == n){
                            cout << i << '\n';
                            return;
                        }
                    }
                }
            }
        }
    }

}

int main(){            ///use cin and printf if you wanna see some REAL SPEED
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    fastio;
    int T = 1;
    prep();
    cin >> T;
    for(int i = 1; i <= T; i++){
        //cout << "test case " << i << endl;
        solve();
    }
    return 0;
}

ll power (ll x, ll y) {
    ll res = 1ll;
    x %= mod;
    if (x == 0)
        return 0;
    while (y > 0) {
        if (y & 1)
            res = (res * x) % mod;
        y = y >> 1ll;
        x = (x * x) % mod;
    }
    return res;
}

ll inv (ll x) {
    ll r = 1ll, t = x, k = mod - 2ll;
    while (k) {
        if (k & 1ll) r = r * t % mod;
        t = (long long) t * t % mod;
        k >>= 1;
    }
    return r;
}

bool isPrime (ll x) {
    if (x == 1)
        return false;
    for (ll i = 2ll; i * i <= x; i++) {
        if (x % i == 0)
            return false;
    }
    return true;
}

ll gcd (ll x, ll y) {
    if (!y)
        return x;
    return gcd (y, x % y);
}

/*
    __builtin_popcount
    __builtin_ctz
    __builtin_clz
*/


#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define st first
#define nd second
#define pb push_back
#define popb pop_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define sortall(x) sort(all(x));
#define deb(x) cout << #x << " = " << x << endl
#define debv(x) cout << #x << ": "; for (int i = 0; i < (x).size(); i++) cout << (x)[i] << ' '; cout << endl
#define PI 3.1415926535897932384626
#define fastio ios_base::sync_with_stdio(false); cin.tie(); cout.tie(); srand(time(NULL)); cout << fixed << setprecision(1)
typedef pair< int ,int >                pii;
typedef pair< long long, long long >    pll;
typedef vector< pii >                   vii;
typedef vector< pll >                   vll;
typedef long long                       ll;
typedef map< int, int >                 mii;
typedef set< pii >                      sii;
typedef set< int >                      si;
typedef vector< int >                   vi;
typedef vector< ll >                    vl;
typedef long double                     ld;
typedef pair< ld, ld >                  pld;
typedef vector< pld >                   vpld;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
//ordered_set t;
//t.insert(val);
//t.find_by_order(i) - returns iterator to the i-th element in set
//t.order_of_key(i) - index of value i

const ll mod = 1e9 + 7;                 /// 1 000 000 007
const ll mod2 = 119 << 23 | 1;          /// 998244353
const ll mod3 = 467'093'870'598'391;    /// big prime
int inf = 1e9 + 7;
ll INF = 1e14 + 9;

///tagliatelle here
///

ll power (ll x, ll y);
ll inv (ll x);
bool isPrime (ll x);
ll gcd (ll x, ll y);

//================================================================================

const int nax = 2e5 + 13;

void prep(){

}

inline int sum(ll x){
    int res = 0;
    while(x){
        res += (x % 10ll);
        x /= 10ll;
    }
    return res;
}

void solve(){

    int n, k;
    cin >> n >> k;
    if(k > 1){
        int c;
        if(k==2 && n%3){
            cout << -1 << endl;
            return;
        }else if(k == 2)
            c = 699997;
        else if(k == 3 || k == 4)
            c = 79989;
        else
            c = 3000;

        for(int i = 0; i <= c; i++){
            int ans = 0;
            for(int j = 0; j <= k; j++)
                ans += sum(i + j);
            if(ans == n){
                cout << i << '\n';
                return;
            }
        }
        cout << -1 << '\n';
    }else{
        if(k == 0){ //construct by hand
            string res;
            while(n >= 9){
                res.pb('9');
                n -= 9;
            }
            if(n > 0){
                res.pb('0' + n);
            }
            reverse(all(res));
            cout << res << '\n';
        }else if(k == 1){
            string res;
            if(n % 2){              //construct as odds are easy to construct
                n++;
                while(n > 18){
                    res.pb('9');
                    n -= 18;
                }
                if(n > 1)
                    res.pb('0' + (n / 2));
                res[0]--;
                reverse(all(res));
                cout << res << '\n';
            }else{                  //optimized search
                if(n < 10){                 //no answer
                    cout << -1 << '\n';
                    return;
                }else if(n <= 98){          //searching for small values bruteforce
                    for(int i = 9; i <= 1000000; i+=10){
                        if(sum(i) + sum(i+1) == n){
                            cout << i << '\n';
                            return;
                        }
                    }
                }else{                      //searching for big values by big jumps (first ocurrences of bigger evens are there)
                    for(ll i = 999989ll; i <= 100000000000ll; i += 1000000ll){
                        if(sum(i) + sum(i+1ll) == n){
                            cout << i << '\n';
                            return;
                        }
                    }
                }
            }
        }
    }

}

int main(){            ///use cin and printf if you wanna see some REAL SPEED
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    fastio;
    int T = 1;
    prep();
    cin >> T;
    for(int i = 1; i <= T; i++){
        solve();
    }
    return 0;
}

ll power (ll x, ll y) {
    ll res = 1ll;
    x %= mod;
    if (x == 0)
        return 0;
    while (y > 0) {
        if (y & 1)
            res = (res * x) % mod;
        y = y >> 1ll;
        x = (x * x) % mod;
    }
    return res;
}

ll inv (ll x) {
    ll r = 1ll, t = x, k = mod - 2ll;
    while (k) {
        if (k & 1ll) r = r * t % mod;
        t = (long long) t * t % mod;
        k >>= 1;
    }
    return r;
}

bool isPrime (ll x) {
    if (x == 1)
        return false;
    for (ll i = 2ll; i * i <= x; i++) {
        if (x % i == 0)
            return false;
    }
    return true;
}

ll gcd (ll x, ll y) {
    if (!y)
        return x;
    return gcd (y, x % y);
}

/*
    __builtin_popcount
    __builtin_ctz
    __builtin_clz
*/


#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define st first
#define nd second
#define pb push_back
#define popb pop_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define sortall(x) sort(all(x));
#define deb(x) cout << #x << " = " << x << endl
#define debv(x) cout << #x << ": "; for (int i = 0; i < (x).size(); i++) cout << (x)[i] << ' '; cout << endl
#define PI 3.1415926535897932384626
#define fastio ios_base::sync_with_stdio(false); cin.tie(); cout.tie(); srand(time(NULL)); cout << fixed << setprecision(1)
typedef pair< int ,int >                pii;
typedef pair< long long, long long >    pll;
typedef vector< pii >                   vii;
typedef vector< pll >                   vll;
typedef long long                       ll;
typedef map< int, int >                 mii;
typedef set< pii >                      sii;
typedef set< int >                      si;
typedef vector< int >                   vi;
typedef vector< ll >                    vl;
typedef long double                     ld;
typedef pair< ld, ld >                  pld;
typedef vector< pld >                   vpld;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
//ordered_set t;
//t.insert(val);
//t.find_by_order(i) - returns iterator to the i-th element in set
//t.order_of_key(i) - index of value i

const ll mod = 1e9 + 7;                 /// 1 000 000 007
const ll mod2 = 119 << 23 | 1;          /// 998244353
const ll mod3 = 467'093'870'598'391;    /// big prime
int inf = 1e9 + 7;
ll INF = 1e14 + 9;

///tagliatelle here
///

ll power (ll x, ll y);
ll inv (ll x);
bool isPrime (ll x);
ll gcd (ll x, ll y);

//================================================================================

const int nax = 2e5 + 13;

void prep(){

}

ll sum(ll x){
    ll res = 0;
    while(x){
        res += (x % 10ll);
        x /= 10ll;
    }
    return res;
}

void solve(){

    int n, k;
    cin >> n >> k;
    if(k > 1){
        for(int i = 0; i < 1000000; i++){
            ll ans = 0;
            for(int j = 0; j <= k; j++)
                ans += sum(i + j);
            if(ans == n){
                cout << i << '\n';
                return;
            }
        }
        cout << -1 << '\n';
    }else{
        if(k == 0){
            string res;
            while(n >= 9){
                res.pb('9');
                n -= 9;
            }
            if(n > 0){
                res.pb('0' + n);
            }
            reverse(all(res));
            cout << res << '\n';
        }else{
            string res;
            if(n % 2){
                //normal
                n++;
                while(n > 18){
                    res.pb('9');
                    n -= 18;
                }
                if(n > 1)
                    res.pb('0' + (n / 2));
                res[0]--;
                reverse(all(res));
                cout << res << '\n';
            }else{
                //fucked up
                if(n < 10){
                    cout << -1 << '\n';
                    return;
                }else if(n <= 62){
                    for(ll i = 0; i <= 10000; i++){
                        if(sum(i) + sum(i+1) == n){
                            cout << i << '\n';
                            return;
                        }
                    }
                }else{
                    for(ll i = 9989ll; i <= 1000000000ll; i += 1000ll){
                        if(sum(i) + sum(i+1) == n){
                            cout << i << '\n';
                            return;
                        }
                    }
                }
            }
        }
    }

}

int main(){            ///use cin and printf if you wanna see some REAL SPEED
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    fastio;
    int T = 1;
    prep();
    cin >> T;
    for(int i = 1; i <= T; i++){
        //cout << "test case " << i << endl;
        solve();
    }
    return 0;
}

ll power (ll x, ll y) {
    ll res = 1ll;
    x %= mod;
    if (x == 0)
        return 0;
    while (y > 0) {
        if (y & 1)
            res = (res * x) % mod;
        y = y >> 1ll;
        x = (x * x) % mod;
    }
    return res;
}

ll inv (ll x) {
    ll r = 1ll, t = x, k = mod - 2ll;
    while (k) {
        if (k & 1ll) r = r * t % mod;
        t = (long long) t * t % mod;
        k >>= 1;
    }
    return r;
}

bool isPrime (ll x) {
    if (x == 1)
        return false;
    for (ll i = 2ll; i * i <= x; i++) {
        if (x % i == 0)
            return false;
    }
    return true;
}

ll gcd (ll x, ll y) {
    if (!y)
        return x;
    return gcd (y, x % y);
}

/*
    __builtin_popcount
    __builtin_ctz
    __builtin_clz
*/