#include <bits/stdc++.h>
using namespace std;
long long t, n, k, ans, temp;
const long long zer = 0;
long long buildnum(long long digsum, bool nine) {
  long long res = 1;
  long long ret = 0;
  if (nine) {
    if (digsum <= 9) return digsum;
    ret = 9;
    digsum -= 9;
    res = 10;
  } else {
    if (digsum <= 8) return digsum;
    ret = 8;
    digsum -= 8;
    res = 10;
  }
  while (digsum > 0) {
    if (digsum <= 9) return res * digsum + ret;
    digsum -= 9;
    ret += 9 * res;
    res *= 10;
  }
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> t;
  while (t--) {
    cin >> n >> k;
    ans = n;
    vector<int> v;
    if (n < k * (k + 1) / 2) {
      cout << -1 << endl;
      continue;
    }
    if (k == 0) {
      if (n % 9 != 0) cout << n % 9;
      for (int i = 0; i < n / 9; i++) cout << 9;
      cout << endl;
      continue;
    } else if (k == 1) {
      if (n % 2 == 1) {
        if (n <= 17)
          cout << n / 2 << endl;
        else {
          n = (n - 17) / 2;
          if (n % 9 != 0) cout << n % 9;
          for (int i = 0; i < n / 9; i++) cout << 9;
          cout << 8;
          cout << endl;
        }
        continue;
      } else {
        if (n < 10) {
          cout << -1 << endl;
          continue;
        } else {
          if (n == 10) {
            cout << 9 << endl;
            continue;
          }
          temp = buildnum((n - 10) / 2, false);
          cout << temp << 9 << endl;
          continue;
        }
      }
    } else if (k == 2) {
      if (n % 3 == 0) {
        ans = (n - 3) / 3;
        if (ans <= 7) {
          cout << ans << endl;
          continue;
        }
        temp = buildnum(ans - 7, true);
        cout << temp << 7 << endl;
        continue;
      }
      cout << -1 << endl;
      continue;
    } else if (k == 3) {
      if (n % 4 == 2) {
        ans = (n - 6) / 4;
        if (ans <= 6) {
          cout << ans << endl;
          continue;
        }
        temp = buildnum(ans - 6, true);
        cout << temp << 6 << endl;
        continue;
      }
      if (n % 4 == 1) {
        if (n < 25) {
          cout << -1 << endl;
          continue;
        }
        ans = (n - 25) / 4;
        if (ans == 0)
          cout << 7 << endl;
        else {
          temp = buildnum(ans, false);
          cout << temp << 7 << endl;
        }
        continue;
      }
      if (n % 4 == 0) {
        if (n < 20) {
          cout << -1 << endl;
          continue;
        }
        ans = (n - 20) / 4;
        if (ans == 0)
          cout << 8 << endl;
        else {
          temp = buildnum(ans, false);
          cout << temp << 8 << endl;
        }
        continue;
      }
      if (n % 4 == 3) {
        if (n < 15) {
          cout << -1 << endl;
          continue;
        }
        ans = (n - 15) / 4;
        if (ans == 0)
          cout << 9 << endl;
        else {
          temp = buildnum(ans, false);
          cout << temp << 9 << endl;
        }
        continue;
      }
    } else if (k == 4) {
      if (n % 5 == 0) {
        ans = (n - 10) / 5;
        if (ans <= 5) {
          cout << ans << endl;
          continue;
        }
        temp = buildnum(ans - 5, true);
        cout << temp << 5 << endl;
        continue;
      }
      if (n % 5 == 1) {
        if (n < 31) {
          cout << -1 << endl;
          continue;
        }
        ans = (n - 31) / 5;
        if (ans == 0)
          cout << 6 << endl;
        else {
          temp = buildnum(ans, false);
          cout << temp << 6 << endl;
        }
        continue;
      }
      if (n % 5 == 2) {
        if (n < 27) {
          cout << -1 << endl;
          continue;
        }
        ans = (n - 27) / 5;
        if (ans == 0)
          cout << 7 << endl;
        else {
          temp = buildnum(ans, false);
          cout << temp << 7 << endl;
        }
        continue;
      }
      if (n % 5 == 3) {
        if (n < 23) {
          cout << -1 << endl;
          continue;
        }
        ans = (n - 23) / 5;
        if (ans == 0)
          cout << 8 << endl;
        else {
          temp = buildnum(ans, false);
          cout << temp << 8 << endl;
        }
        continue;
      }
      if (n % 5 == 4) {
        if (n < 19) {
          cout << -1 << endl;
          continue;
        }
        ans = (n - 19) / 5;
        if (ans == 0)
          cout << 9 << endl;
        else {
          temp = buildnum(ans, false);
          cout << temp << 9 << endl;
        }
        continue;
      }
    } else if (k == 5) {
      if (n % 6 == 3) {
        ans = (n - 15) / 6;
        if (ans <= 4) {
          cout << ans << endl;
          continue;
        }
        temp = buildnum(ans - 4, true);
        cout << temp << 4 << endl;
        continue;
      }
      if (n % 6 == 0) {
        if (ans < 24) {
          cout << -1 << endl;
          continue;
        }
        if (ans == 24) {
          cout << 9 << endl;
          continue;
        }
        if (ans == 30) {
          cout << 7 << endl;
          continue;
        }
        if (ans == 36) {
          cout << 5 << endl;
          continue;
        }
        ans = (n - 36) / 6;
        temp = buildnum(ans, false);
        cout << temp << 5 << endl;
        continue;
      }
      cout << -1 << endl;
      continue;
    } else if (k == 6) {
      if (n % 7 == 0) {
        ans = (n - 21) / 7;
        if (ans <= 3) {
          cout << ans << endl;
          continue;
        }
        temp = buildnum(ans - 3, true);
        cout << temp << 3 << endl;
        continue;
      }
      if (n % 7 == 1) {
        if (n < 36) {
          cout << -1 << endl;
          continue;
        }
        ans = (n - 36) / 7;
        if (ans == 0)
          cout << 6 << endl;
        else {
          temp = buildnum(ans, false);
          cout << temp << 6 << endl;
        }
        continue;
      }
      if (n % 7 == 2) {
        if (n < 30) {
          cout << -1 << endl;
          continue;
        }
        ans = (n - 30) / 7;
        if (ans == 0)
          cout << 9 << endl;
        else {
          temp = buildnum(ans, false);
          cout << temp << 9 << endl;
        }
        continue;
      }
      if (n % 7 == 3) {
        if (n < 38) {
          cout << -1 << endl;
          continue;
        }
        ans = (n - 38) / 7;
        if (ans == 0)
          cout << 5 << endl;
        else {
          temp = buildnum(ans, false);
          cout << temp << 5 << endl;
        }
        continue;
      }
      if (n % 7 == 4) {
        if (n < 32) {
          cout << -1 << endl;
          continue;
        }
        ans = (n - 32) / 7;
        if (ans == 0)
          cout << 8 << endl;
        else {
          temp = buildnum(ans, false);
          cout << temp << 8 << endl;
        }
        continue;
      }
      if (n % 7 == 5) {
        if (n < 40) {
          cout << -1 << endl;
          continue;
        }
        ans = (n - 40) / 7;
        if (ans == 0)
          cout << 4 << endl;
        else {
          temp = buildnum(ans, false);
          cout << temp << 4 << endl;
        }
        continue;
      }
      if (n % 7 == 6) {
        if (n < 34) {
          cout << -1 << endl;
          continue;
        }
        ans = (n - 34) / 7;
        if (ans == 0)
          cout << 7 << endl;
        else {
          temp = buildnum(ans, false);
          cout << temp << 7 << endl;
        }
        continue;
      }
    } else if (k == 7) {
      if (n % 8 == 4) {
        ans = (n - 28) / 8;
        if (ans <= 2) {
          cout << ans << endl;
          continue;
        }
        temp = buildnum(ans - 2, true);
        cout << temp << 2 << endl;
        continue;
      }
      if (n % 8 == 3) {
        if (n < 43) {
          cout << -1 << endl;
          continue;
        }
        ans = (n - 43) / 8;
        if (ans == 0)
          cout << 3 << endl;
        else {
          temp = buildnum(ans, false);
          cout << temp << 3 << endl;
        }
        continue;
      }
      if (n % 8 == 2) {
        if (n < 42) {
          cout << -1 << endl;
          continue;
        }
        ans = (n - 42) / 8;
        if (ans == 0)
          cout << 4 << endl;
        else {
          temp = buildnum(ans, false);
          cout << temp << 4 << endl;
        }
        continue;
      }
      if (n % 8 == 1) {
        if (n < 41) {
          cout << -1 << endl;
          continue;
        }
        ans = (n - 41) / 8;
        if (ans == 0)
          cout << 5 << endl;
        else {
          temp = buildnum(ans, false);
          cout << temp << 5 << endl;
        }
        continue;
      }
      if (n % 8 == 0) {
        if (n < 40) {
          cout << -1 << endl;
          continue;
        }
        ans = (n - 40) / 8;
        if (ans == 0)
          cout << 6 << endl;
        else {
          temp = buildnum(ans, false);
          cout << temp << 6 << endl;
        }
        continue;
      }
      if (n % 8 == 7) {
        if (n < 39) {
          cout << -1 << endl;
          continue;
        }
        ans = (n - 39) / 8;
        if (ans == 0)
          cout << 7 << endl;
        else {
          temp = buildnum(ans, false);
          cout << temp << 7 << endl;
        }
        continue;
      }
      if (n % 8 == 6) {
        if (n < 38) {
          cout << -1 << endl;
          continue;
        }
        ans = (n - 38) / 8;
        if (ans == 0)
          cout << 8 << endl;
        else {
          temp = buildnum(ans, false);
          cout << temp << 8 << endl;
        }
        continue;
      }
      if (n % 8 == 5) {
        if (n < 37) {
          cout << -1 << endl;
          continue;
        }
        ans = (n - 37) / 8;
        if (ans == 0)
          cout << 9 << endl;
        else {
          temp = buildnum(ans, false);
          cout << temp << 9 << endl;
        }
        continue;
      }
    } else if (k == 8) {
      if (n % 9 == 0) {
        ans = (n - 36) / 9;
        if (ans <= 1) {
          cout << ans << endl;
          continue;
        }
        temp = buildnum(ans - 1, true);
        cout << temp << 1 << endl;
        continue;
      }
      cout << -1 << endl;
      continue;
    } else if (k == 9) {
      if (n % 10 == 5) {
        ans = (n - 45) / 10;
        if (ans <= 0) {
          cout << ans << endl;
          continue;
        }
        temp = buildnum(ans, true);
        cout << temp << 0 << endl;
        continue;
      }
      long long rema = (n + 5) % 10;
      if (n < 45 + rema) {
        cout << -1 << endl;
        continue;
      }
      ans = (n - 45 - rema) / 10;
      if (ans == 0)
        cout << rema << endl;
      else {
        temp = buildnum(ans, false);
        cout << temp << rema << endl;
      }
      continue;
    }
  }
}
