#include <bits/stdc++.h>
using namespace std;
int prime(int x) {
  if (x <= 1) return 0;
  if (x <= 3) return 1;
  if (x % 2 == 0 || x % 3 == 0) return 0;
  for (int i = 5; i * i <= x; i += 6) {
    if (x % i == 0 || x % (i + 2) == 0) return 0;
  }
  return 1;
}
int main() {
  long long x;
  cin >> x;
  unsigned long long a, b;
  while (x-- > 0) {
    cin >> a >> b;
    cout << (a - 1) * 9 + b << endl;
  }
  return 0;
}
