#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
const long long mod = 2e18 + 7;
const long long inf = 0x3f3f3f3f;
const long double pi = acos(-1.0);
long long n, m, c, x, y, t, k;
long long a[10][300], b[maxn];
vector<long long> g[10];
long long go(int num) {
  long long res = 0;
  while (num) {
    res += num % 10;
    num /= 10;
  }
  return res;
}
string s;
void run() {
  cin >> n >> k;
  if (k == 0) {
    if (n % 9) {
      cout << n % 9;
      n -= (n % 9);
    }
    while (n) {
      cout << 9;
      n -= 9;
    }
    cout << '\n';
    return;
  }
  cout << a[k][n] << '\n';
}
int main() {
  std::ios::sync_with_stdio(false);
  for (int i = 1; i <= 150; i++) {
    for (int j = 0; j < 10; j++) a[j][i] = -1;
  }
  for (int i = 0; i <= 100100; i++) {
    b[i] = go(i);
  }
  for (int x, i = 0; i < 100000; i++) {
    x = 0;
    for (int j = 0; j < 10; j++) {
      x += b[i + j];
      if (x > 150) break;
      if (a[j][x] != -1) continue;
      a[j][x] = i;
    }
  }
  long long tmp = 0;
  for (int i = 44; i <= 148; i++) {
    tmp = 1;
    while (a[1][i] / tmp) {
      tmp *= 10;
    }
    tmp /= 10;
    if (a[1][i] / tmp == 9) {
      a[1][i + 2] = a[1][i] + tmp * 10;
    } else {
      a[1][i + 2] = a[1][i] + tmp;
    }
  }
  for (int i = 45; i <= 147; i += 3) {
    tmp = 1;
    while (a[2][i] / tmp) {
      tmp *= 10;
    }
    tmp /= 10;
    if (a[2][i] / tmp == 9) {
      a[2][i + 3] = a[2][i] + tmp * 10;
    } else {
      a[2][i + 3] = a[2][i] + tmp;
    }
  }
  cin >> t;
  while (t--) run();
  return 0;
}
