#include <bits/stdc++.h>
long long get_int();
long long max(long long a, long long b) {
  if (a > b) {
    return a;
  }
  return b;
}
long long min(long long a, long long b) {
  if (a < b) {
    return a;
  }
  return b;
}
int main() {
  int t = get_int();
  while (t-- != 0) {
    long long n = get_int();
    long long k = get_int();
    printf("%lld\n", 9 * (n - 1) + k);
  }
  return 0;
}
long long get_int() {
  long long ret = 0;
  char c = getchar();
  int sgn;
  while (1) {
    if (c == EOF) {
      return EOF;
    }
    if (c >= '0' && c <= '9') {
      sgn = 1;
      break;
    }
    if (c == '-') {
      c = getchar();
      if (c < '0' || c > '9') {
        continue;
      }
      sgn = -1;
      break;
    }
    c = getchar();
  }
  while (1) {
    ret = (ret << 3) + (ret << 1) + c - '0';
    c = getchar();
    if (c < '0' || c > '9') {
      return sgn * ret;
    }
  }
}
