//构造
#include<bits/stdc++.h>
using namespace std;
#define int long long
int a,b,c ;
signed main()
{ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);cin>>a;while(a--){cin>>b>>c;int m=b,k=0;while(m){m/=10;k++;}int v=0;for(int i=1;i<=9;i++){v=v*10+i;}v=v*10+c;for(int i=1;i<=k;i++){v=v*10;}int pp=v%b;if(pp==0){cout<<v/b<<endl;}else{v+=(b-pp);cout<<v/b<<endl;}}
}