#include <bits/stdc++.h>
using namespace std;
const int SZ = 200100;
const int INF = 1e9 + 10;
const int mod = 998244353;
const long double eps = 1e-8;
long long read() {
  long long n = 0;
  char a = getchar();
  bool flag = 0;
  while (a > '9' || a < '0') {
    if (a == '-') flag = 1;
    a = getchar();
  }
  while (a <= '9' && a >= '0') {
    n = n * 10 + a - '0', a = getchar();
  }
  if (flag) n = -n;
  return n;
}
int get(int x) {
  int ans = 0;
  while (x) ans += x % 10, x /= 10;
  return ans;
}
int S(int x) {
  while (x >= 10) {
    x = get(x);
  }
  return x;
}
int main() {
  int T = read();
  while (T--) {
    long long k = read(), x = read();
    cout << x + k * 9 - 9 << endl;
  }
  return 0;
}
