import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.string;

void solve() {
    auto s = readln.split.map!(to!long);
    auto K = s[0];
    auto X = s[1];
    long ans;

    if (X == 9) {
        ans = 9 * K;
    } else {
        ans = 9 * (K - 1) + X;
    }

    ans.writeln;
}

void main() {
    auto T = readln.chomp.to!int;
    while (T--) solve;
}
