#include <bits/stdc++.h>
using namespace std;
int n,k,t;
string m;
int main(){
cin >> n;
for(int i = 1; i <= n; i++){
cin >> m >> k;
for(int j = 1; j <= m.size(); j++){
if(m[j] - 48){
t++;
}
}
if(t < k){
cout << -1;
continue;
}
for(int j = 1; j <= k; j++){
cout << 9;
}
for(int j = 1; j < m.size(); j++){
cout << 0;
}
cout << "\n";
}
return 0;
}