#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("unroll-loops")
using namespace std;
bool ispalin(string str) {
  long long l = 0;
  long long h = str.size() - 1;
  while (h > l) {
    if (str[l++] != str[h--]) return 0;
  }
  return 1;
}
void isprime(long long n) {
  bool prime[n + 1];
  memset(prime, true, sizeof(prime));
  for (long long p = 2; p * p <= n; p++) {
    if (prime[p] == true)
      for (long long i = p * p; i <= n; i += p) prime[i] = false;
  }
  for (long long p = 2; p <= n; p++)
    if (prime[p]) cout << p << " ";
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(0);
  long long test = 1;
  while (test--) {
    long long n;
    cin >> n;
    long long x, y;
    for (long long i = 0; i < n; i++) {
      cin >> x >> y;
      cout << 9 * (x - 1) + y << endl;
    }
  }
  return 0;
}
