#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int a, b, c, d, l = 0, i = 0, j = 0, n = 0, k = 0;
  cin >> a;
  while (a--) {
    cin >> b >> c;
    cout << 9 * (b - 1) + c << endl;
  }
  return 0;
}
