#include <bits/stdc++.h>
int n;
long long x, k, ans;
int main() {
  scanf("%d", &n);
  while (n--) {
    scanf("%lld %lld", &k, &x);
    ans = (k - 1) * 9 + x;
    printf("%lld\n", ans);
  }
  return 0;
}
