#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T &t) {
  int f = 0, c = getchar();
  t = 0;
  while (!isdigit(c)) f |= c == '-', c = getchar();
  while (isdigit(c)) t = t * 10 + c - 48, c = getchar();
  if (f) t = -t;
}
template <typename T, typename... Args>
inline void read(T &t, Args &...args) {
  read(t);
  read(args...);
}
const int maxn = 35;
int S[maxn];
int main() {
  int t;
  read(t);
  for (int i = 1; i <= t; i++) {
    long long k, x;
    read(k, x);
    cout << (k - 1) * 9 + x << endl;
  }
}
