#include <bits/stdc++.h>
using namespace std;
int arr[105];
vector<int> graph[105];
int node;
int dp[105][105];
int main() {
  int x, y;
  long long T, n, k;
  vector<int> v;
  map<int, int> freq;
  int n0, n1, n2;
  cin >> T;
  while (T--) {
    cin >> n >> k;
    long long temp = k, sum = 0;
    int rem = 0;
    while (temp > 0) {
      temp += rem;
      rem = temp % n;
      sum += temp / n;
      temp /= n;
    }
    k += sum;
    if (k % n == 0) {
      cout << k + 1 << endl;
    } else
      cout << k << endl;
  }
  return 0;
}
