#include <bits/stdc++.h>
using namespace std;
const long long aN = 2e5 + 5;
const long long mod = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(false);
  int tc = 1;
  cin >> tc;
  while (tc--) {
    long long n, k;
    cin >> k >> n;
    if (k == 1)
      cout << n << endl;
    else
      cout << ((k - 1) * 9) + n << endl;
  }
  return 0;
}
