#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 7;
const long long M = 1e9 + 7;
const long long H = 1e5 + 7;
const long long B = 1e4 + 7;
const long long A = 1e6 + 7;
map<long long, long long> mp, pm;
deque<long long> v, vc, ve;
deque<char> p, pe;
deque<string> ts, ss;
deque<double> sd;
long long b, c, a[1001], y, d, e, f, cnt, ans, r, n, l = 2, R, k, u, m, x, z, s,
                                                     mx;
double t, cnt1;
string g, h, o;
bool re, rt;
set<long long> st;
vector<long long> vec(N);
vector<pair<long long, long long> > rp;
char q, w;
int main() {
  long long a, b, n;
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    cin >> a >> b;
    cout << (a - 1) * 9 + b << endl;
  }
}
