#include <bits/stdc++.h>
int main() {
  unsigned long long int n, k, x;
  scanf("%llu", &n);
  for (int i = 0; i < n; i++) {
    scanf("%llu %llu", &k, &x);
    printf("%llu\n", (k - 1) * 9 + x);
  }
}
