#include <bits/stdc++.h>
#pragma GCC optimize "O2"
using namespace std;
const unsigned long long int MOD = 1000000007;
const long double PI = 2 * acos(0.0);
vector<long long int> ga(long long int n) {
  vector<long long int> a;
  for (long long int i = 0; i < n; i++) {
    long long int p;
    cin >> p;
    a.push_back(p);
  }
  return move(a);
}
vector<unsigned long long int> gau(unsigned long long int n) {
  vector<unsigned long long int> a;
  for (unsigned long long int i = 0; i < n; i++) {
    unsigned long long int p;
    cin >> p;
    a.push_back(p);
  }
  return move(a);
}
vector<string> gas(unsigned long long int n) {
  vector<string> a;
  for (unsigned long long int i = 0; i < n; i++) {
    string p;
    cin >> p;
    a.push_back(p);
  }
  return move(a);
}
template <typename T, typename A>
void pa(vector<T, A> const &a) {
  for (T p : a) {
    cout << p << " ";
  }
  cout << "\n";
}
void yes() { cout << "YES\n"; }
void no() { cout << "NO\n"; }
void yesno(int f) {
  if (f)
    yes();
  else
    no();
}
void solve() {
  unsigned long long int k, x;
  cin >> k >> x;
  unsigned long long int f = 9 * k;
  f -= (9 - x);
  cout << f << endl;
}
int main(void) {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
