#include <bits/stdc++.h>
using namespace std;
const long long N = 3e5 + 10;
const double PI = acos(-1.0);
struct Complex {
  double x, y;
  Complex(double _x = 0.0, double _y = 0.0) {
    x = _x;
    y = _y;
  }
  Complex operator-(const Complex &b) const {
    return Complex(x - b.x, y - b.y);
  }
  Complex operator+(const Complex &b) const {
    return Complex(x + b.x, y + b.y);
  }
  Complex operator*(const Complex &b) const {
    return Complex(x * b.x - y * b.y, x * b.y + y * b.x);
  }
};
void change(Complex y[], long long len) {
  long long i, j, k;
  for (i = 1, j = len / 2; i < len - 1; i++) {
    if (i < j) {
      swap(y[i], y[j]);
    }
    k = len / 2;
    while (j >= k) {
      j -= k;
      k /= 2;
    }
    if (j < k) {
      j += k;
    }
  }
  return;
}
void fft(Complex y[], long long len, long long on) {
  change(y, len);
  for (long long h = 2; h <= len; h <<= 1) {
    Complex wn(cos(-on * 2 * PI / h), sin(-on * 2 * PI / h));
    for (long long j = 0; j < len; j += h) {
      Complex w(1, 0);
      for (long long k = j; k < j + h / 2; k++) {
        Complex u = y[k];
        Complex t = w * y[k + h / 2];
        y[k] = u + t;
        y[k + h / 2] = u - t;
        w = w * wn;
      }
    }
  }
  if (on == -1) {
    for (long long i = 0; i < len; i++) {
      y[i].x /= len;
    }
  }
}
const long long MOD = 1e9 + 7;
const long long INV_2 = 5e8 + 4;
inline void FWT(long long c[], long long N, long long tf_utf) {
  for (long long i = 1; i < N; i <<= 1) {
    long long tmp = i << 1;
    for (long long j = 0; j < N; j += tmp) {
      for (long long k = 0; k < i; k++) {
        long long x = c[j + k], y = c[j + k + i];
        if (tf_utf) {
          c[j + k] = x + y;
          if (c[j + k] >= MOD) {
            c[j + k] -= MOD;
          }
          c[j + k + i] = x - y;
          if (c[j + k + i] < 0) {
            c[j + k + i] += MOD;
          }
        } else {
          c[j + k] = (long long)(x + y) * INV_2 % MOD;
          c[j + k + i] = (long long)(x - y + MOD) * INV_2 % MOD;
        }
      }
    }
  }
}
string ss[N][10];
long long aa[N], n, k;
long long calc(long long i, long long j, long long k, long long l) {
  if (k + l <= 9)
    return (l + 1) * j + (1 + l) * l / 2;
  else {
    long long p = 9 - k;
    long long sum = (p + 1) * j + (1 + p) * p / 2;
    return sum + calc(0, j - i * 9 + 1 - k, 0, l - p - 1);
  }
}
const long long MAXN = 20010;
long long t1[MAXN];
long long t2[MAXN];
long long c[MAXN];
bool cmp(long long *r, long long a, long long b, long long l) {
  return r[a] == r[b] && r[a + l] == r[b + l];
}
void da(long long str[], long long sa[], long long rank[], long long height[],
        long long n, long long m) {
  n++;
  long long i, j, p, *x = t1, *y = t2;
  for (i = 0; i < m; i++) {
    c[i] = 0;
  }
  for (i = 0; i < n; i++) {
    c[x[i] = str[i]]++;
  }
  for (i = 1; i < m; i++) {
    c[i] += c[i - 1];
  }
  for (i = n - 1; i >= 0; i--) {
    sa[--c[x[i]]] = i;
  }
  for (j = 1; j <= n; j <<= 1) {
    p = 0;
    for (i = n - j; i < n; i++) {
      y[p++] = i;
    }
    for (i = 0; i < n; i++) {
      if (sa[i] >= j) {
        y[p++] = sa[i] - j;
      }
    }
    for (i = 0; i < m; i++) {
      c[i] = 0;
    }
    for (i = 0; i < n; i++) {
      c[x[y[i]]]++;
    }
    for (i = 1; i < m; i++) {
      c[i] += c[i - 1];
    }
    for (i = n - 1; i >= 0; i--) {
      sa[--c[x[y[i]]]] = y[i];
    }
    swap(x, y);
    p = 1;
    x[sa[0]] = 0;
    for (i = 1; i < n; i++) {
      x[sa[i]] = cmp(y, sa[i - 1], sa[i], j) ? p - 1 : p++;
    }
    if (p >= n) {
      break;
    }
    m = p;
  }
  long long k = 0;
  n--;
  for (i = 0; i <= n; i++) {
    rank[sa[i]] = i;
  }
  for (i = 0; i < n; i++) {
    if (k) {
      k--;
    }
    j = sa[rank[i] - 1];
    while (str[i + k] == str[j + k]) {
      k++;
    }
    height[rank[i]] = k;
  }
}
long long _rank[MAXN], height[MAXN];
long long RMQ[MAXN];
long long mm[MAXN];
long long best[20][MAXN];
void initRMQ(long long n) {
  mm[0] = -1;
  for (long long i = 1; i <= n; i++) {
    mm[i] = ((i & (i - 1)) == 0) ? mm[i - 1] + 1 : mm[i - 1];
  }
  for (long long i = 1; i <= n; i++) {
    best[0][i] = i;
  }
  for (long long i = 1; i <= mm[n]; i++) {
    for (long long j = 1; j + (1 << i) - 1 <= n; j++) {
      long long a = best[i - 1][j];
      long long b = best[i - 1][j + (1 << (i - 1))];
      if (RMQ[a] < RMQ[b]) {
        best[i][j] = a;
      } else {
        best[i][j] = b;
      }
    }
  }
}
long long askRMQ(long long a, long long b) {
  long long t;
  t = mm[b - a + 1];
  b -= (1 << t) - 1;
  a = best[t][a];
  b = best[t][b];
  return RMQ[a] < RMQ[b] ? a : b;
}
long long lcp(long long a, long long b) {
  a = _rank[a];
  b = _rank[b];
  if (a > b) {
    swap(a, b);
  }
  return height[askRMQ(a + 1, b)];
}
char str[MAXN];
long long r[MAXN];
long long sa[MAXN];
const long long ha = 510;
long long uN, vN;
long long g[ha][ha];
long long linker[ha];
bool used[ha];
bool dfs(long long u) {
  for (long long v = 0; v < vN; v++) {
    if (g[u][v] && !used[v]) {
      used[v] = true;
      if (linker[v] == -1 || dfs(linker[v])) {
        linker[v] = u;
        return true;
      }
    }
  }
  return false;
}
long long hungary() {
  long long res = 0;
  memset(linker, -1, sizeof(linker));
  for (long long u = 0; u < uN; u++) {
    memset(used, false, sizeof(used));
    if (dfs(u)) {
      res++;
    }
  }
  return res;
}
const long long MAXV = 300;
struct Lpoint {
  double x, y;
};
struct Llineseg {
  Lpoint a, b;
};
struct Ldir {
  double dx, dy;
};
struct Lline {
  Lpoint p;
  Ldir dir;
};
struct Lrad {
  Lpoint Sp;
  Ldir dir;
};
struct Lround {
  Lpoint co;
  double r;
};
signed main_gasd() {
  while (scanf("%s", str) == 1) {
    long long len = (long long)strlen(str);
    long long n = 2 * len + 1;
    for (long long i = 0; i < len; i++) {
      r[i] = str[i];
    }
    for (long long i = 0; i < len; i++) {
      r[len + 1 + i] = str[len - 1 - i];
    }
    r[len] = 1;
    r[n] = 0;
    da(r, sa, _rank, height, n, 128);
    for (long long i = 1; i <= n; i++) {
      RMQ[i] = height[i];
    }
    initRMQ(n);
    long long ans = 0, st = 0;
    long long tmp;
    for (long long i = 0; i < len; i++) {
      tmp = lcp(i, n - i);
      if (2 * tmp > ans) {
        ans = 2 * tmp;
        st = i - tmp;
      }
      tmp = lcp(i, n - i - 1);
      if (2 * tmp - 1 > ans) {
        ans = 2 * tmp - 1;
        st = i - tmp + 1;
      }
    }
    str[st + ans] = 0;
    printf("%s\n", str + st);
  }
  return 0;
}
void check(string &a, string b) {
  if (!a.size())
    a = b;
  else if (a.size() > b.size())
    a = b;
  else if (a.size() == b.size())
    if (a > b) a = b;
}
string get(long long i, long long j, long long k) {
  long long now = -1;
  long long tmp = j - i * 9 - k;
  string s, t = "";
  if (tmp) {
    if (tmp < 8)
      s += ('0' + tmp);
    else {
      tmp -= 8;
      if (tmp % 9) s += ('0' + tmp % 9);
      for (long long i = 0; i <= tmp / 9 - 1; i++) s += '9';
      s += '8';
    }
  }
  for (long long j = 0; j <= i - 1; j++) s += '9';
  s += ('0' + k);
  return s;
}
char name[][15] = {"monday", "tuesday",  "wednesday", "thursday",
                   "friday", "saturday", "sunday"};
signed maigeafsn() {
  long long d, m, y, a;
  printf("Day: ");
  scanf("%d", &d);
  printf("Month: ");
  scanf("%d", &m);
  printf("Year: ");
  scanf("%d", &y);
  if (m == 1 || m == 2) {
    m += 12;
    y--;
  }
  if ((y < 1752) || (y == 1752 && m < 9) || (y == 1752 && m == 9 && d < 3)) {
    a = (d + 2 * m + 3 * (m + 1) / 5 + y + y / 4 + 5) % 7;
  } else {
    a = (d + 2 * m + 3 * (m + 1) / 5 + y + y / 4 - y / 100 + y / 400) % 7;
  }
  printf("it's a %s\n", name[a]);
  return 0;
}
signed main() {
  std::ios::sync_with_stdio(false);
  long long up = 150;
  for (long long i = 0; i <= 17; i++)
    for (long long k = 0; k <= 9; k++)
      for (long long j = 9 * i + k; j <= up; j++)
        for (long long l = 0; l <= 9; l++) {
          long long now = calc(i, j, k, l);
          if (now <= up) check(ss[now][l], get(i, j, k));
        }
  long long t;
  cin >> t;
  while (t--) {
    cin >> n >> k;
    if (!ss[n][k].size())
      cout << -1 << '\n';
    else
      cout << ss[n][k] << '\n';
  }
  return 0;
}
