#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
const int INF = 0x3f3f3f3f;
const int iinf = 1 << 30;
const long long linf = 2e18;
const int MOD = 1000000007;
void print(int x) {
  cout << x << endl;
  exit(0);
}
void PRINT(string x) {
  cout << x << endl;
  exit(0);
}
void douout(double x) { printf("%lf\n", x + 0.0000000001); }
int main() {
  int n;
  cin >> n;
  while (n--) {
    int x;
    long long k;
    cin >> k >> x;
    long long a = 9LL * (k - 1LL) + 1LL * x;
    cout << a << endl;
  }
  return 0;
}
