import java.util.*;
import java.io.BufferedInputStream;
import java.io.InputStream;
import java.io.PrintWriter;

public class a
{
	public static void main(String[] arg)
	{
		new a();
	}
	public a()
	{
		//JoltyScanner in = new JoltyScanner(System.in);
		Scanner in = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int row = in.nextInt();
		int col = in.nextInt();
		char[][] grid = new char[row][col];
		for(int i = 0; i < row; i++) grid[i] = in.next().toCharArray();
		Pair source = new Pair(in.nextInt()-1, in.nextInt()-1);
		Pair sink = new Pair(in.nextInt()-1, in.nextInt()-1);
		int check = findIntact(grid, sink, row, col);
		boolean flag = false;
		if(source.equals(sink))
		{
			if(check >= 1) flag = true;
			else flag = false;
		}
		else if(source.adjacent(sink))
		{
			if(grid[sink.row][sink.col] == 'X') flag = true;
			else
			{
				if(check >= 2) flag = true;
				else flag = false;
			}
		}
		else
		{
			if(findPath(source, sink, grid))
			{
				if(grid[sink.row][sink.col] == 'X') flag = true;
				else
				{
					if(check >= 2) flag = true;
					else flag = false;
				}
			}
			else flag = false;
		}
		System.out.println(flag ? "YES" : "NO");
		in.close();
		out.close();
	}
	public boolean findPath(Pair start, Pair end, char[][] grid)
	{
		ArrayDeque<Pair> q = new ArrayDeque<Pair>();
		q.add(start);
		boolean answer = false;
		int[] dx = {0 ,0, -1, 1};
		int[] dy = {-1, 1, 0, 0};
		while(q.size() > 0)
		{
			Pair temp = q.poll();
			if(!temp.isValid(grid)) continue;
			if(temp.equals(end)) return true;
			if(!temp.equals(start) && grid[temp.row][temp.col] == 'X') continue;
			grid[temp.row][temp.col] = 'X';
			for(int i = 0; i < 4; i++)
			{
				q.add(new Pair(temp.row+dx[i], temp.col+dy[i]));
			}
		}
		return answer;
	}
	public int findIntact(char[][] grid, Pair cur, int maxRow, int maxCol)
	{
		int answer = 0;
		int x = cur.row;
		int y = cur.col;
		if(x != 0)
			if(grid[x-1][y] == '.') answer++;

		if(x != maxRow-1)
			if(grid[x+1][y] == '.') answer++;

		if(y != 0)
			if(grid[x][y-1] == '.') answer++;

		if(y != maxCol-1)
			if(grid[x][y+1] == '.') answer++;

		return answer;
	}
	class Pair
	{
		public int row, col;
		public Pair(int a, int b)
		{
			row = a;
			col = b;
		}
		public boolean equals(Pair a)
		{
			return row == a.row && col == a.col;
		}
		public boolean adjacent(Pair a)
		{
			return Math.abs(row-a.row) + Math.abs(col-a.col) == 1;
		}
		public boolean isValid(char[][] grid)
		{
			if(row < 0 || row >= grid.length) return false;
			if(col < 0 || col >= grid[row].length) return false;
			return true;
		}
	}
	public class JoltyScanner
	{
	    public static final int BUFFER_SIZE = 1 << 16;
		public static final char NULL_CHAR = (char) -1;

	    byte[] buffer = new byte[BUFFER_SIZE];
		boolean EOF_FLAG = false;
		int bufferIdx = 0, size = 0;
		char c = NULL_CHAR;
		BufferedInputStream in;

		public JoltyScanner(InputStream in)
		{
			this.in = new BufferedInputStream(in, BUFFER_SIZE);
		}

		public int nextInt()
		{
			long x = nextLong();
			if (x > Integer.MAX_VALUE || x < Integer.MIN_VALUE)
			{
				throw new ArithmeticException("Scanned value overflows integer");
			}
			return (int) x;
		}

		public long nextLong()
		{
			boolean negative = false;
			if (c == NULL_CHAR)
			{
				c = nextChar();
			}
			for (; !EOF_FLAG && (c < '0' || c > '9'); c = nextChar())
			{
				if (c == '-')
				{
					negative = true;
				}
			}
			checkEOF();
			long res = 0;
			for (; c >= '0' && c <= '9'; c = nextChar())
			{
				res = (res << 3) + (res << 1) + c - '0';
			}
			return negative ? -res : res;
		}

	    public char nextChar()
	    {
			if (EOF_FLAG)
			{
				return NULL_CHAR;
			}
			while (bufferIdx == size)
			{
				try
				{
					size = in.read(buffer);
					if (size == -1)
					{
						throw new Exception();
					}
				}
				catch (Exception e)
				{
					EOF_FLAG = true;
					return NULL_CHAR;
				}
				if (size == -1)
				{
					size = BUFFER_SIZE;
				}
				bufferIdx = 0;
			}
			return (char) buffer[bufferIdx++];
		}

	    public void checkEOF()
	    {
			if (EOF_FLAG)
			{
				throw new EndOfFileException();
			}
		}

		public class EndOfFileException extends RuntimeException
		{
		}
	}
}

/*
1 2
.X
1 2
1 1
NO

1 2
.X
1 2
1 2
YES

1 1
X
1 1
1 1

1 2
XX
1 1
1 1
NO
*/


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @author Don Li
 */
public class IceCave {

    int[] dx = {0, 0, -1, 1};
    int[] dy = {-1, 1, 0, 0};

    int n, m;
    int[][] A;
    int r1, c1, r2, c2;

    void solve() {
        n = in.nextInt();
        m = in.nextInt();
        A = new int[n][m];
        for (int i = 0; i < n; i++) {
            String s = in.nextToken();
            for (int j = 0; j < m; j++) {
                if (s.charAt(j) == '.') A[i][j] = 1;
                else A[i][j] = 0;
            }
        }
        r1 = in.nextInt() - 1;
        c1 = in.nextInt() - 1;
        r2 = in.nextInt() - 1;
        c2 = in.nextInt() - 1;

        if (r1 == r2 && c1 == c2) {
            for (int i = 0; i < 4; i++) {
                int x = r2 + dx[i], y = c2 + dy[i];
                if (x >= 0 && x < n && y >= 0 && y < m && A[x][y] == 1) {
                    out.println("YES");
                    return;
                }
            }
            out.println("NO");
            return;
        }

        if (dfs(r1, c1)) {
            if (A[r2][c2] == 0) {
                out.println("YES");
                return;
            }
            int entry = 1;
            for (int i = 0; i < 4; i++) {
                int nx = r2 + dx[i], ny = c2 + dy[i];
                if (nx >= 0 && nx < n && ny >= 0 && ny < m) {
                    if (nx == r1 && ny == c1 || A[nx][ny] == 1) entry++;
                }
            }
            if (entry >= 2) {
                out.println("YES");
                return;
            }
        }
        out.println("NO");
    }

    boolean dfs(int x, int y) {
        A[x][y] = 0;
        for (int i = 0; i < 4; i++) {
            int nx = x + dx[i], ny = y + dy[i];
            if (nx >= 0 && nx < n && ny >= 0 && ny < m) {
                if (nx == r2 && ny == c2) {
                    return true;
                }
                if (A[nx][ny] > 0) {
                    if (dfs(nx, ny)) return true;
                }
            }
        }
        return false;
    }

    public static void main(String[] args) {
        in = new FastScanner(new BufferedReader(new InputStreamReader(System.in)));
        out = new PrintWriter(System.out);
        new IceCave().solve();
        out.close();
    }

    static FastScanner in;
    static PrintWriter out;

    static class FastScanner {
        BufferedReader in;
        StringTokenizer st;

        public FastScanner(BufferedReader in) {
            this.in = in;
        }

        public String nextToken() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(in.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextToken());
        }

        public long nextLong() {
            return Long.parseLong(nextToken());
        }

        public double nextDouble() {
            return Double.parseDouble(nextToken());
        }
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @author Don Li
 */
public class IceCave {

    int[] dx = {0, 0, -1, 1};
    int[] dy = {-1, 1, 0, 0};

    int n, m;
    int[][] A;
    int r1, c1, r2, c2;

    boolean[][] vis;

    void solve() {
        n = in.nextInt();
        m = in.nextInt();
        A = new int[n][m];
        for (int i = 0; i < n; i++) {
            String s = in.nextToken();
            for (int j = 0; j < m; j++) {
                if (s.charAt(j) == '.') A[i][j] = 1;
                else A[i][j] = 0;
            }
        }
        r1 = in.nextInt() - 1;
        c1 = in.nextInt() - 1;
        r2 = in.nextInt() - 1;
        c2 = in.nextInt() - 1;

        if (r1 == r2 && c1 == c2) {
            for (int i = 0; i < 4; i++) {
                int x = r2 + dx[i], y = c2 + dy[i];
                if (x >= 0 && x < n && y >= 0 && y < m && A[x][y] == 1) {
                    out.println("YES");
                    return;
                }
            }
            out.println("NO");
            return;
        }

        vis = new boolean[n][m];
        if (dfs(r1, c1)) {
            if (A[r2][c2] == 0) {
                out.println("YES");
                return;
            }
            int entry = 0;
            for (int i = 0; i < 4; i++) {
                int nx = r2 + dx[i], ny = c2 + dy[i];
                if (nx >= 0 && nx < n && ny >= 0 && ny < m) {
                    if (vis[nx][ny] || A[nx][ny] == 1) entry++;
                }
            }
            if (entry >= 2) {
                out.println("YES");
                return;
            }
        }
        out.println("NO");
    }

    boolean dfs(int x, int y) {
        A[x][y] = 0;
        vis[x][y] = true;
        for (int i = 0; i < 4; i++) {
            int nx = x + dx[i], ny = y + dy[i];
            if (nx >= 0 && nx < n && ny >= 0 && ny < m) {
                if (nx == r2 && ny == c2) {
                    return true;
                }
                if (A[nx][ny] > 0) {
                    if (dfs(nx, ny)) return true;
                }
            }
        }
        return false;
    }

    public static void main(String[] args) {
        in = new FastScanner(new BufferedReader(new InputStreamReader(System.in)));
        out = new PrintWriter(System.out);
        new IceCave().solve();
        out.close();
    }

    static FastScanner in;
    static PrintWriter out;

    static class FastScanner {
        BufferedReader in;
        StringTokenizer st;

        public FastScanner(BufferedReader in) {
            this.in = in;
        }

        public String nextToken() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(in.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextToken());
        }

        public long nextLong() {
            return Long.parseLong(nextToken());
        }

        public double nextDouble() {
            return Double.parseDouble(nextToken());
        }
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @author Don Li
 */
public class IceCave {

    int[] dx = new int[]{-1, 0, 0, 1};
    int[] dy = new int[]{0, -1, 1, 0};

    int n, m;
    char[][] g;
    boolean[][] vis;
    int r1, c1, r2, c2;

    void solve() {
        n = in.nextInt();
        m = in.nextInt();
        g = new char[n][];
        for (int i = 0; i < n; i++) {
            g[i] = in.nextToken().toCharArray();
        }
        r1 = in.nextInt() - 1;
        c1 = in.nextInt() - 1;
        r2 = in.nextInt() - 1;
        c2 = in.nextInt() - 1;

        if (r1 == r2 && c1 == c2) {
            boolean ok = false;
            for (int i = 0; i < 4; i++) {
                int x = r1 + dx[i], y = c1 + dy[i];
                if (x >= 0 && x < n && y >= 0 && y < m && g[x][y] == '.') {
                    ok = true;
                    break;
                }
            }
            if (ok) out.println("YES");
            else out.println("NO");
            return;
        }

        vis = new boolean[n][m];
        dfs(r1, c1);

        if (!vis[r2][c2]) {
            out.println("NO");
            return;
        }

        if (g[r2][c2] == 'X') {
            out.println("YES");
            return;
        }

        int cnt = 0;
        for (int i = 0; i < 4; i++) {
            int x = r2 + dx[i], y = c2 + dy[i];
            if (x >= 0 && x < n && y >= 0 && y < m && (g[x][y] == '.' || x == r1 && y == c1)) cnt++;
        }
        if (cnt >= 2) out.println("YES");
        else out.println("NO");
    }

    void dfs(int r, int c) {
        vis[r][c] = true;
        for (int i = 0; i < 4; i++) {
            int x = r + dx[i], y = c + dy[i];
            if (x >= 0 && x < n && y >= 0 && y < m && g[x][y] == '.' || x == r2 && y == c2) {
                if (!vis[x][y]) dfs(x, y);
            }
        }
    }

    public static void main(String[] args) {
        in = new FastScanner(new BufferedReader(new InputStreamReader(System.in)));
        out = new PrintWriter(System.out);
        new IceCave().solve();
        out.close();
    }

    static FastScanner in;
    static PrintWriter out;

    static class FastScanner {
        BufferedReader in;
        StringTokenizer st;

        public FastScanner(BufferedReader in) {
            this.in = in;
        }

        public String nextToken() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(in.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextToken());
        }

        public long nextLong() {
            return Long.parseLong(nextToken());
        }

        public double nextDouble() {
            return Double.parseDouble(nextToken());
        }
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @author Don Li
 */
public class IceCave {

    int[] dx = {0, 0, -1, 1};
    int[] dy = {-1, 1, 0, 0};

    int n, m;
    int[][] A;
    int r1, c1, r2, c2;

    void solve() {
        n = in.nextInt();
        m = in.nextInt();
        A = new int[n][m];
        for (int i = 0; i < n; i++) {
            String s = in.nextToken();
            for (int j = 0; j < m; j++) {
                if (s.charAt(j) == '.') A[i][j] = 1;
                else A[i][j] = 0;
            }
        }
        r1 = in.nextInt() - 1;
        c1 = in.nextInt() - 1;
        r2 = in.nextInt() - 1;
        c2 = in.nextInt() - 1;

        if (r1 == r2 && c1 == c2) {
            for (int i = 0; i < 4; i++) {
                int x = r2 + dx[i], y = c2 + dy[i];
                if (x >= 0 && x < n && y >= 0 && y < m && A[x][y] == 1) {
                    out.println("YES");
                    return;
                }
            }
            out.println("NO");
            return;
        }

        if (dfs(r1, c1)) {
            if (A[r2][c2] == 0) {
                out.println("YES");
                return;
            }
            for (int i = 0; i < 4; i++) {
                int x = r2 + dx[i], y = c2 + dy[i];
                if (x >= 0 && x < n && y >= 0 && y < m && A[x][y] == 1) {
                    out.println("YES");
                    return;
                }
            }
        }
        out.println("NO");
    }

    boolean dfs(int x, int y) {
        if (x == r2 && y == c2) return true;
        if (!(x == r1 && y == c1)) A[x][y] = 0;
        for (int i = 0; i < 4; i++) {
            int nx = x + dx[i], ny = y + dy[i];
            if (nx >= 0 && nx < n && ny >= 0 && ny < m) {
                if (A[nx][ny] == 1 || nx == r2 && ny == c2) {
                    if (dfs(nx, ny)) return true;
                }
            }
        }
        return false;
    }

    public static void main(String[] args) {
        in = new FastScanner(new BufferedReader(new InputStreamReader(System.in)));
        out = new PrintWriter(System.out);
        new IceCave().solve();
        out.close();
    }

    static FastScanner in;
    static PrintWriter out;

    static class FastScanner {
        BufferedReader in;
        StringTokenizer st;

        public FastScanner(BufferedReader in) {
            this.in = in;
        }

        public String nextToken() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(in.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextToken());
        }

        public long nextLong() {
            return Long.parseLong(nextToken());
        }

        public double nextDouble() {
            return Double.parseDouble(nextToken());
        }
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @author Don Li
 */
public class IceCave {

    int[] dx = {0, 0, -1, 1};
    int[] dy = {-1, 1, 0, 0};

    int n, m;
    int[][] A;
    int r1, c1, r2, c2;

    void solve() {
        n = in.nextInt();
        m = in.nextInt();
        A = new int[n][m];
        for (int i = 0; i < n; i++) {
            String s = in.nextToken();
            for (int j = 0; j < m; j++) {
                if (s.charAt(j) == '.') A[i][j] = 1;
                else A[i][j] = 0;
            }
        }
        r1 = in.nextInt() - 1;
        c1 = in.nextInt() - 1;
        r2 = in.nextInt() - 1;
        c2 = in.nextInt() - 1;

        if (dfs(r1, c1)) {
            if (A[r2][c2] == 0) {
                out.println("YES");
                return;
            }
            for (int i = 0; i < 4; i++) {
                int x = r2 + dx[i], y = c2 + dy[i];
                if (x >= 0 && x < n && y >= 0 && y < m && A[x][y] == 1) {
                    out.println("YES");
                    return;
                }
            }
        }
        out.println("NO");
    }

    boolean dfs(int x, int y) {
        if (x == r2 && y == c2) return true;
        if (!(x == r1 && y == c1)) A[x][y] = 0;
        for (int i = 0; i < 4; i++) {
            int nx = x + dx[i], ny = y + dy[i];
            if (nx >= 0 && nx < n && ny >= 0 && ny < m) {
                if (A[nx][ny] == 1 || nx == r2 && ny == c2) {
                    if (dfs(nx, ny)) return true;
                }
            }
        }
        return false;
    }

    public static void main(String[] args) {
        in = new FastScanner(new BufferedReader(new InputStreamReader(System.in)));
        out = new PrintWriter(System.out);
        new IceCave().solve();
        out.close();
    }

    static FastScanner in;
    static PrintWriter out;

    static class FastScanner {
        BufferedReader in;
        StringTokenizer st;

        public FastScanner(BufferedReader in) {
            this.in = in;
        }

        public String nextToken() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(in.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextToken());
        }

        public long nextLong() {
            return Long.parseLong(nextToken());
        }

        public double nextDouble() {
            return Double.parseDouble(nextToken());
        }
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @author Don Li
 */
public class IceCave {

    int[] dx = {0, 0, -1, 1};
    int[] dy = {-1, 1, 0, 0};

    int n, m;
    int[][] A;
    int r1, c1, r2, c2;

    void solve() {
        n = in.nextInt();
        m = in.nextInt();
        A = new int[n][m];
        for (int i = 0; i < n; i++) {
            String s = in.nextToken();
            for (int j = 0; j < m; j++) {
                if (s.charAt(j) == '.') A[i][j] = 1;
                else A[i][j] = 0;
            }
        }
        r1 = in.nextInt() - 1;
        c1 = in.nextInt() - 1;
        r2 = in.nextInt() - 1;
        c2 = in.nextInt() - 1;

        if (r1 == r2 && c1 == c2) {
            for (int i = 0; i < 4; i++) {
                int x = r2 + dx[i], y = c2 + dy[i];
                if (x >= 0 && x < n && y >= 0 && y < m && A[x][y] == 1) {
                    out.println("YES");
                    return;
                }
            }
            out.println("NO");
            return;
        }

        if (dfs(r1, c1)) {
            out.println("YES");
            return;
        }
        out.println("NO");
    }

    boolean dfs(int x, int y) {
        if (x == r2 && y == c2) {
            if (A[r2][c2] == 0) return true;
            else {
                for (int i = 0; i < 4; i++) {
                    int nx = r2 + dx[i], ny = c2 + dy[i];
                    if (nx >= 0 && nx < n && ny >= 0 && ny < m && A[nx][ny] == 1) {
                        return true;
                    }
                }
                return false;
            }
        }

        for (int i = 0; i < 4; i++) {
            int nx = x + dx[i], ny = y + dy[i];
            if (nx >= 0 && nx < n && ny >= 0 && ny < m) {
                if (nx == r2 && ny == c2) {
                    if (dfs(nx, ny)) return true;
                } else if (A[nx][ny] == 1) {
                    A[nx][ny] = 0;
                    if (dfs(nx, ny)) return true;
                    A[nx][ny] = 1;
                }
            }
        }
        return false;
    }

    public static void main(String[] args) {
        in = new FastScanner(new BufferedReader(new InputStreamReader(System.in)));
        out = new PrintWriter(System.out);
        new IceCave().solve();
        out.close();
    }

    static FastScanner in;
    static PrintWriter out;

    static class FastScanner {
        BufferedReader in;
        StringTokenizer st;

        public FastScanner(BufferedReader in) {
            this.in = in;
        }

        public String nextToken() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(in.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextToken());
        }

        public long nextLong() {
            return Long.parseLong(nextToken());
        }

        public double nextDouble() {
            return Double.parseDouble(nextToken());
        }
    }
}


import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int t = in.nextInt();

        for(int i=0;i<t;i++){
            //System.out.println();
            int input =in.nextInt();
            int k = in.nextInt();
            solve(input,k);
        }
    }

    private static void solve(int input,int k) {
        int index=0,number=1;
        while(index<k){
            if(number%input!=0) index++;
            number++;
        }
        System.out.println(number-1);

    }

}


import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int t = in.nextInt();

        for(int i=0;i<t;i++){
            //System.out.println();
            int input =in.nextInt();
            int k = in.nextInt();
            solve(input,k);
        }
    }

    private static void solve(int input,int k) {
        int round = k/(input-1);
        k-=round*(input-1);
        if(k==0) {
            System.out.println(round*input-1);
            return;
        }
        int last  =  round*input;
        System.out.println(last+k);

    }

}


import java.util.*;
import java.lang.*;
import java.io.*;

public class GFG {
	public static void main (String[] args)throws IOException {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		int t=Integer.parseInt(br.readLine());
		while(t-->0)
		{
		    String str[]=br.readLine().trim().split(" ");
		    int n=Integer.parseInt(str[0]);
		    int k=Integer.parseInt(str[1]);
		    System.out.println(solution.fuck(n,k));
		}
	}

static class solution{
    public static long fuck(int n,int k)
    {
        return (k+(int)Math.floor((double)(k-1)/(double)(n-1)));

    }
}
}


import java.util.*;
import java.lang.*;
import java.io.*;

public class GFG {
	public static void main (String[] args)throws IOException {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		int t=Integer.parseInt(br.readLine());
		while(t-->0)
		{
		    String str[]=br.readLine().trim().split(" ");
		    int n=Integer.parseInt(str[0]);
		    int k=Integer.parseInt(str[1]);
		    System.out.println(solution.fuck(n,k));
		}
	}

static class solution{
    public static long fuck(int n,int k)
    {

        n-=2;
        k--;
        int j=1;
        int res=1;
        while(j<=k)
        {
            for(int i=0;i<n&&j<=k;i++)
            {
                res++;
                j++;
            }
            if(j<=k)
            {
                res+=2;
                j++;
            }
        }
        return res;
    }
}
}


import java.util.*;
import java.util.ArrayList;
public class Main{
     static class Pair{
     int x;
     int y;
       Pair(){

       }
       Pair(int x,int y){
       this.x=x;
       this.y=y;
       }
     }

    public static void main(String[] args)
    {
    Scanner param = new Scanner(System.in);
    int end=param.nextInt();
    while(end-->0){
    int n=param.nextInt();
    int k=param.nextInt();
    int sum=0;
    sum=(n-1);
    int i=1;
    while(sum<k){
    sum=(n-1)*i;
    i++;
    }
    if(sum!=k){
        sum=sum-(n-1);
    }
    else{
        i--;
    }
    System.out.println(sum+(i-1));

    }
}
}


import java.util.*;
import java.util.ArrayList;
public class Main{
     static class Pair{
     int x;
     int y;
       Pair(){

       }
       Pair(int x,int y){
       this.x=x;
       this.y=y;
       }
     }

    public static void main(String[] args)
    {
    Scanner param = new Scanner(System.in);
    int end=param.nextInt();
    while(end-->0){
    int n=param.nextInt();
    int k=param.nextInt();
    int sum=0;
    sum=(n-1);
    int i=1;
    while(sum<k){
    sum=(n-1)*i;
    i++;
    }
    //System.out.println(i);
    if(sum!=k){
        sum=sum-(n-1);
        i=i-1;
    }
    else{
       i= Math.max(0,i-2);

    }
    System.out.println(sum+i);

    }
}
}


import java.util.*;
import java.util.ArrayList;
public class Main{
     static class Pair{
     int x;
     int y;
       Pair(){

       }
       Pair(int x,int y){
       this.x=x;
       this.y=y;
       }
     }

    public static void main(String[] args)
    {
    Scanner param = new Scanner(System.in);
    int end=param.nextInt();
    while(end-->0){
    int n=param.nextInt();
    int k=param.nextInt();
   int dabba=k/(n-1);
   int rem=k%(n-1);
   if(rem==0){
   System.out.println(n*dabba-1);
   }
   else{
   System.out.println(n*dabba+rem);
   }

    }
}
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Tarek
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CKThNotDivisibleByN solver = new CKThNotDivisibleByN();
        solver.solve(1, in, out);
        out.close();
    }

    static class CKThNotDivisibleByN {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int t = in.nextInt();
            while (t-- > 0) {
                int n = in.nextInt();
                int k = in.nextInt();
                int f = (k - 1) / (n - 1);
                out.println(k + f);
            }
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Tarek
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CKThNotDivisibleByN solver = new CKThNotDivisibleByN();
        solver.solve(1, in, out);
        out.close();
    }

    static class CKThNotDivisibleByN {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int t = in.nextInt();
            while (t-- > 0) {
                int n = in.nextInt();
                int k = in.nextInt();
                out.println((int) (k + Math.floor((k - 1) / (n - 1))));
            }
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}


/******************************************************************************

                            Online Java Compiler.
                Code, Compile, Run and Debug java program online.
Write your code in this editor and press "Run" button to execute it.

*******************************************************************************/
import java.util.*;
public class Main
{
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int t = in.nextInt();
		while(t-->0)
		{
		    long n = in.nextLong();
		    long k = in.nextLong();
		    long tmp = k/(n-1);
		    long i=tmp*n;

		    i+=(k%(n-1));

		    if((k%(n-1))==0)
		    System.out.println(i-1);
		    else
		    System.out.println(i);

		}

	}
}


import java.util.*;
public class Main
{
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int t = in.nextInt();
		while(t-->0)
		{
		    long n = in.nextLong();
		    long k = in.nextLong();
		    int c = 0;
		    long i=0;
		    for(i=n;c<k;i+=n)
		    {
		        c+=n-1;
		    }
		    i-=(2*n);
		    c-=(n-1);
		    i+=(k-c);
		    System.out.println(i);

		}

	}
}


/******************************************************************************

                            Online Java Compiler.
                Code, Compile, Run and Debug java program online.
Write your code in this editor and press "Run" button to execute it.

*******************************************************************************/
import java.util.*;
public class Main
{
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int t = in.nextInt();
		while(t-->0)
		{
		    long n = in.nextLong();
		    long k = in.nextLong();
		    int c = 0;
		    long i=0;
		    for(i=n;c<k;i+=n)
		    {
		        c+=n-1;
		    }
		    i-=(2*n);
		    c-=(n-1);
		    i+=(k-c);
		    System.out.println(i);

		}

	}
}


import java.util.*;
import java.io.FileNotFoundException;
import java.io.*;

public class Main {
    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        int n = nextInt();
        long[] a = new long[n];
        long[] b = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = nextInt();
            b[i] = nextInt();
        }
        for (int i = 0; i < n; i++) {
            if (b[i] < a[i]) {
                out.println(b[i]);
            } else if (b[i] == a[i]) {
                a[i]++;
                out.println(a[i]);
            } else {

                long ha = b[i] + (b[i]/(a[i]-1));
                if (b[i]%a[i]==0)   {
                    ha--;
                    out.println(ha);
                }
                else {
                    out.println(ha);
                }
            }
        }

        out.close();

    }

    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static PrintWriter out = new PrintWriter(System.out);
    static StringTokenizer in = new StringTokenizer("");

    public static String nextToken() throws IOException {
        while (in == null || !in.hasMoreTokens()) {
            in = new StringTokenizer(br.readLine());
        }
        return in.nextToken();
    }

    public static int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    public static double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    public static long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }
}


import java.util.*;
import java.io.FileNotFoundException;
import java.io.*;

public class Main {
    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        int n = nextInt();
        long[] a = new long[n];
        long[] b = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = nextInt();
            b[i] = nextInt();
        }
        for (int i = 0; i < n; i++) {
            if (b[i] < a[i]) {
                out.println(b[i]);
            } else if (b[i] == a[i]) {
                a[i]++;
                out.println(a[i]);
            } else {

                long ha = b[i] + (b[i]/(a[i]-1));
                if (b[i]%a[i]==0 || ha%a[i]==0)   {
                    ha--;
                    out.println(ha);
                }
                else {
                    out.println(ha);
                }
            }
        }

        out.close();

    }

    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static PrintWriter out = new PrintWriter(System.out);
    static StringTokenizer in = new StringTokenizer("");

    public static String nextToken() throws IOException {
        while (in == null || !in.hasMoreTokens()) {
            in = new StringTokenizer(br.readLine());
        }
        return in.nextToken();
    }

    public static int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    public static double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    public static long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }
}


import java.util.*;
import java.io.FileNotFoundException;
import java.io.*;

public class Main {
    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        int n = nextInt();
        long[] a = new long[n];
        long[] b = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = nextInt();
            b[i] = nextInt();
        }
        for (int i = 0; i < n; i++) {
            if (b[i] < a[i]) {
                out.println(b[i]);
            } else if (b[i] == a[i]) {
                a[i]++;
                out.println(a[i]);
            } else {
                long ha = b[i];
                long aa = a[i];
                b[i] = b[i] - (b[i] - ha / a[i]);
                ha++;
                while (b[i] != 0) {
                    if (ha % a[i] == 0) {
                        ha++;
                    } else {
                        b[i]--;
                        ha++;
                    }
                }
                ha--;
                out.println(ha);
            }
        }

        out.close();

    }

    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static PrintWriter out = new PrintWriter(System.out);
    static StringTokenizer in = new StringTokenizer("");

    public static String nextToken() throws IOException {
        while (in == null || !in.hasMoreTokens()) {
            in = new StringTokenizer(br.readLine());
        }
        return in.nextToken();
    }

    public static int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    public static double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    public static long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }
}


import java.util.*;
import java.io.FileNotFoundException;
import java.io.*;

public class Main {
    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        int n = nextInt();
        long[] a = new long[n];
        long[] b = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = nextInt();
            b[i] = nextInt();
        }
        for (int i = 0; i < n; i++) {
            if (b[i] < a[i]) {
                out.println(b[i]);
            } else if (b[i] == a[i]) {
                a[i]++;
                out.println(a[i]);
            } else {

                long ha = b[i] + (b[i]/(a[i]-1));
                if ( ha%a[i]==0)   {
                    ha--;
                    out.println(ha);
                }
                else {
                    out.println(ha);
                }
            }
        }

        out.close();

    }

    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static PrintWriter out = new PrintWriter(System.out);
    static StringTokenizer in = new StringTokenizer("");

    public static String nextToken() throws IOException {
        while (in == null || !in.hasMoreTokens()) {
            in = new StringTokenizer(br.readLine());
        }
        return in.nextToken();
    }

    public static int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    public static double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    public static long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }
}


import java.util.Scanner;

public class Main{
	public static void main(String[] args) {

		Scanner scn=new Scanner(System.in);

		int t=scn.nextInt();

		for(int i=0;i<t;i++) {
			long x=scn.nextLong();
			long y=scn.nextLong();

			long count=0;
			long N=1;
			while(true) {

				if(N%x!=0) {
					count++;
				}
				if(count==y) {
					System.out.println(N);
					break;
				}
				N++;
			}
		}
		scn.close();
	}
}


import java.io.*;
import java.util.*;

import static java.lang.Integer.*;
import static java.lang.Long.*;

public class DIv_4_640C {

    static long getKthNotDivisble(long n, long k) {
        long left = 1, right = (n * k) + 1, res = right;
        while (left <= right) {
            long mid = left + (right - left) / 2;
            long nonDivisible = mid - (mid / n);
            if (nonDivisible < k) {
                left = mid + 1;
            } else {
                res = mid;
                right = mid - 1;
            }
        }
        return res;
    }

    public static void main(String[] args) throws IOException {
        BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter prnt = new PrintWriter(System.out);
        StringTokenizer st;
        int t = parseInt(read.readLine());
        for (int i = 0; i < t; i++) {
            st = new StringTokenizer(read.readLine());
            long n = parseLong(st.nextToken()), k = parseLong(st.nextToken());
            prnt.println(getKthNotDivisble(n, k));
        }
        prnt.close();
    }
}


import java.io.PrintWriter;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        PrintWriter printWriter = new PrintWriter(System.out);
        int t = scanner.nextInt();
        int result;
        while (t-- > 0) {
            int n = scanner.nextInt();
            int k = scanner.nextInt();
            result = k + (k - 1) / (n - 1);
            printWriter.println(result);
        }

        printWriter.close();
    }

}


import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        //PrintWriter printWriter = new PrintWriter(System.out);
        int t = scanner.nextInt();
        int result;
        while (t-- > 0) {
            int n = scanner.nextInt();
            int k = scanner.nextInt();
            result = k + (k - 1) / (n - 1);
            System.out.println(result);
       //     printWriter.println(result);
        }

       // printWriter.close();
    }

}


/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
	    Scanner in = new Scanner(System.in);
		int test = in.nextInt();
        while (test-->0)
        {
            long n = in.nextLong();
            long k = in.nextLong();

            int ans=0;
            if(k<n){
                System.out.println(k);
            }
            else{
                ans+=k;
                long temp=0;
                while(k>=n)
                {
                    if(k>=n)
                      temp=k%n;
                    k=k/n;
                    ans+=k;
                    k += temp;
                }
                System.out.println(ans);
            }
        }
	}
}


/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
	    Scanner in = new Scanner(System.in);
		int test = in.nextInt();
        while (test-->0)
        {
            long n = in.nextLong();
            long k = in.nextLong();

            int ans=0;
            if(k<n){
                System.out.println(k);
            }
            else{
                ans+=k;
                long temp=0;
                while(k>1)
                {
                    if(k>=n)
                      temp=k%n;
                    k=k/n;
                    ans+=k;
                    k += temp;
                }
                System.out.println(ans);
            }
        }
	}
}


/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
	    Scanner in = new Scanner(System.in);
		int test = in.nextInt();
        while (test-->0)
        {
            int n = in.nextInt();
            int k = in.nextInt();

            int ans=0;
            if(k<n){
                System.out.println(k);
            }
            else{
                ans+=k;
                int temp=0;
                while(k>1)
                {
                    if(k>=n)
                      temp=k%n;
                    k=k/n;
                    ans+=k;
                    k += temp;
                }
                System.out.println(ans);
            }
        }
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * Place here class purpose.
 *
 * @author Kirill
 * @since 21.10.2020
 */
public class Task1352C {
    public static void main(String[] args) throws IOException {
        Task1352C task1352C = new Task1352C();
        task1352C.resolve();
    }

    private void resolve() throws IOException {
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        int testCount = Integer.parseInt(bufferedReader.readLine());

        StringBuilder result = new StringBuilder();
        for (int i = 0; i < testCount; i++) {
            String[] strings = bufferedReader.readLine().split(" ");
            int divider = Integer.parseInt(strings[0]);
            int needNumber = Integer.parseInt(strings[1]);

            int left = 0;
            while ((needNumber - left + 1) / divider > 0) {
                int tmp = (needNumber / 3) * 3 + 1;
                needNumber += (needNumber - left + 1) / divider;
                left = tmp;
            }

            result.append(needNumber).append("\n");
        }

        System.out.println(result);
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * Place here class purpose.
 *
 * @author Kirill
 * @since 21.10.2020
 */
public class Task1352C {
    public static void main(String[] args) throws IOException {
        Task1352C task1352C = new Task1352C();
        task1352C.resolve();
    }

    private void resolve() throws IOException {
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        int testCount = Integer.parseInt(bufferedReader.readLine());

        StringBuilder result = new StringBuilder();
        for (int i = 0; i < testCount; i++) {
            String[] strings = bufferedReader.readLine().split(" ");
            int divider = Integer.parseInt(strings[0]);
            int needNumber = Integer.parseInt(strings[1]);

            int left = 1;
            while ((needNumber - left + 1) / divider > 0) {
                int tmp = (needNumber / divider) * divider + 1;
                needNumber += (needNumber - left + 1) / divider;
                left = tmp;
            }

            result.append(needNumber).append("\n");
        }

        System.out.println(result);
    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Pranay2516
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, FastReader in, PrintWriter out) {
            int t = in.nextInt();
            while (t-- > 0) {
                long n = in.nextInt(), k = in.nextInt(), s = 1, e = 2 * k, mid = 0, ans = 0;
                while (s < e) {
                    mid = (s + e) / 2;
                    if (mid - mid / n >= k) {
                        ans = mid;
                        e = mid;
                    } else s = mid + 1;
                }
                out.println(ans);
            }
        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private FastReader.SpaceCharFilter filter;

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {

            if (numChars == -1)
                throw new InputMismatchException();

            if (curChar >= numChars) {

                curChar = 0;

                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (numChars <= 0)
                    return -1;
            }

            return buf[curChar++];
        }

        public int nextInt() {

            int c = read();

            while (isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-') {
                sgn = -1;
                c = read();
            }

            int res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();

                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));

            return res * sgn;
        }

        public boolean isSpaceChar(int c) {

            if (filter != null)
                return filter.isSpaceChar(c);

            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Pranay2516
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, FastReader in, PrintWriter out) {
            int t = in.nextInt();
            while (t-- > 0) {
                long n = in.nextInt(), k = in.nextInt();
                long p = k / (n - 1);
                if (n == k && n == 2) out.println(2);
                else if (n == k) out.println(n * p + 1);
                else if (k < n) out.println(k);
                else if (n % 2 == 0 && k % 2 == 0) {
                    if (p * n + k - p * (n - 1) % n == 0) out.println(k + p);
                    else out.println(k + p - 1);
                } else out.println(Math.min(p * n + k % n, p * n + (n - k % n)));
            }
        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private FastReader.SpaceCharFilter filter;

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {

            if (numChars == -1)
                throw new InputMismatchException();

            if (curChar >= numChars) {

                curChar = 0;

                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (numChars <= 0)
                    return -1;
            }

            return buf[curChar++];
        }

        public int nextInt() {

            int c = read();

            while (isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-') {
                sgn = -1;
                c = read();
            }

            int res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();

                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));

            return res * sgn;
        }

        public boolean isSpaceChar(int c) {

            if (filter != null)
                return filter.isSpaceChar(c);

            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Pranay2516
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, FastReader in, PrintWriter out) {
            int t = in.nextInt();
            while (t-- > 0) {
                long n = in.nextInt(), k = in.nextInt();
                out.println(1 + n * ((k - 1) / (n - 1)) + (k - 1) % (n - 1));
            }
        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private FastReader.SpaceCharFilter filter;

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {

            if (numChars == -1)
                throw new InputMismatchException();

            if (curChar >= numChars) {

                curChar = 0;

                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (numChars <= 0)
                    return -1;
            }

            return buf[curChar++];
        }

        public int nextInt() {

            int c = read();

            while (isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-') {
                sgn = -1;
                c = read();
            }

            int res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();

                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));

            return res * sgn;
        }

        public boolean isSpaceChar(int c) {

            if (filter != null)
                return filter.isSpaceChar(c);

            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Pranay2516
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, FastReader in, PrintWriter out) {
            int t = in.nextInt();
            while (t-- > 0) {
                int n = in.nextInt(), k = in.nextInt();
                int p = k / (n - 1);
                out.println(n % 2 != 0 || n == k ? ((long) n) * p + 1 : ((long) n) * p - 1);
            }
        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private FastReader.SpaceCharFilter filter;

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {

            if (numChars == -1)
                throw new InputMismatchException();

            if (curChar >= numChars) {

                curChar = 0;

                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (numChars <= 0)
                    return -1;
            }

            return buf[curChar++];
        }

        public int nextInt() {

            int c = read();

            while (isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-') {
                sgn = -1;
                c = read();
            }

            int res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();

                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));

            return res * sgn;
        }

        public boolean isSpaceChar(int c) {

            if (filter != null)
                return filter.isSpaceChar(c);

            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Pranay2516
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, FastReader in, PrintWriter out) {
            int t = in.nextInt();
            while (t-- > 0) {
                long n = in.nextInt(), k = in.nextInt();
                long p = k / (n - 1);
                if (n == k) out.println(n * p + 1);
                else if (k < n) out.println(k);
                else if (n % 2 == 0 && k % 2 == 0) {
                    if (p * n + k - p * (n - 1) % n == 0) out.println(k + p);
                    else out.println(k + p - 1);
                } else out.println(Math.min(p * n + k % n, p * n + (n - k % n)));
            }
        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private FastReader.SpaceCharFilter filter;

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {

            if (numChars == -1)
                throw new InputMismatchException();

            if (curChar >= numChars) {

                curChar = 0;

                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (numChars <= 0)
                    return -1;
            }

            return buf[curChar++];
        }

        public int nextInt() {

            int c = read();

            while (isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-') {
                sgn = -1;
                c = read();
            }

            int res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();

                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));

            return res * sgn;
        }

        public boolean isSpaceChar(int c) {

            if (filter != null)
                return filter.isSpaceChar(c);

            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}


import java.util.*;
import java.io.*;

public class NotDivisible640C{
	static class FastReader {

        BufferedReader br;
        StringTokenizer st;

        private FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

	 int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
	}

	int[] nextIntArrayOne(int n) {
				int[] a = new int[n+1];
				for (int i = 0; i < n+1; i++)
					a[i] = nextInt();
				return a;
	}

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

	public static void main(String[] args) {
		FastReader s =new FastReader();
		int t = s.nextInt();
		StringBuilder str = new StringBuilder();
		while(t-- >0) {
			long  n =s.nextInt();
			long k = s.nextInt();
			long lb = 1;
			long ub = 2*k;
			while(lb<ub) {
				long mid = (lb+ub)/2;
				if(mid-mid/n>=k) {
						ub = mid;
				}else lb = mid+1;
			}
			str.append(lb).append("\n");
		}
		System.out.println(str);
	}

}


import java.util.*;
import java.io.*;

public class NotDivisible640C{
	static class FastReader {

        BufferedReader br;
        StringTokenizer st;

        private FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

	 int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
	}

	int[] nextIntArrayOne(int n) {
				int[] a = new int[n+1];
				for (int i = 0; i < n+1; i++)
					a[i] = nextInt();
				return a;
	}

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

	public static void main(String[] args) {
		FastReader s =new FastReader();
		int t = s.nextInt();
		StringBuilder str = new StringBuilder();
		while(t-- >0) {
			long  n =s.nextInt();
			long k = s.nextInt();
			long total = n;
			long d = n-1;
			while(d<k) {
				d+=n-1;
				total+=n;
			}

			long dif = d-k;
			str.append(total-1-dif).append("\n");

		}
		System.out.println(str);
	}

}


import java.util.*;
import java.io.*;

public class NotDivisible640C{
	static class FastReader {

        BufferedReader br;
        StringTokenizer st;

        private FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

	 int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
	}

	int[] nextIntArrayOne(int n) {
				int[] a = new int[n+1];
				for (int i = 0; i < n+1; i++)
					a[i] = nextInt();
				return a;
	}

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

	public static void main(String[] args) {
		FastReader s =new FastReader();
		int t = s.nextInt();
		StringBuilder str = new StringBuilder();
		while(t-- >0) {
			long  n =s.nextInt();
			long k = s.nextInt();
			if(k<n) {
				str.append(k).append("\n");
				continue;
			}
			if(k==n) {
				str.append(n+1).append("\n");
				continue;
			}
			long total = k+(n-k%n);
			long d = total-total/n;

			while(d<k) {
				total+=n;
				d+=n-1;
			}

			long dif = d-k;
			str.append(total-1-dif).append("\n");
		}
		System.out.println(str);
	}

}


import java.util.*;
public class Main{
     public static void main(String ... string){
          Scanner sc = new Scanner(System.in);
          int t = sc.nextInt();
          while(t-- > 0){
               int n = sc.nextInt();
               int k = sc.nextInt();
               System.out.println((n-l)/(k-1));
          }
     }
}


import java.util.*;
import java.io.*;

public class Main {

	public static void main(String[] args) {
		InputReader in = new InputReader(System.in);
	    int t = in.readInt();
	    while(t-- > 0) {
	    int n = in.readInt();
	    int k = in.readInt();
	    int temp = 1;
	    for(int i = 1; true; i++) {
	    	temp = i*n;
	    	k -= n-1;
	    	if(k < n) {
	    		System.out.println(temp + k);
	    		break;
	    	}
	      }
	    }
	}
}

class InputReader {

	private InputStream stream;
	private byte[] buf = new byte[1024];
	private int curChar;
	private int numChars;
	private SpaceCharFilter filter;

	public InputReader(InputStream stream) {
		this.stream = stream;
	}

	public int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

	public int readInt() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	public String readString() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

	public long readLong() {
		int c = read();
		while (isSpaceChar(c)) {
			c = read();
		}
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		long res = 0;
		do {
			if (c < '0' || c > '9') {
				throw new InputMismatchException();
			}
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	public boolean isSpaceChar(int c) {
		if (filter != null)
			return filter.isSpaceChar(c);
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

	public String next() {
		return readString();
	}

	public interface SpaceCharFilter {
		public boolean isSpaceChar(int ch);
	}
}


import java.util.*;
import java.io.*;

public class Main {

	public static void main(String[] args) {
		InputReader in = new InputReader(System.in);
	    int t = in.readInt();
	    while(t-- > 0) {
	    int n = in.readInt();
	    int k = in.readInt();
	    for(int i = 0; i<1000000009; i++) {
	    	if(i % n == 0) continue;
	    	else k--;
	    	if(k == 0) {
	    		System.out.println(i);
	    		break;
	    	}
	      }
	    }
	}
}

class InputReader {

	private InputStream stream;
	private byte[] buf = new byte[1024];
	private int curChar;
	private int numChars;
	private SpaceCharFilter filter;

	public InputReader(InputStream stream) {
		this.stream = stream;
	}

	public int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

	public int readInt() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	public String readString() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

	public long readLong() {
		int c = read();
		while (isSpaceChar(c)) {
			c = read();
		}
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		long res = 0;
		do {
			if (c < '0' || c > '9') {
				throw new InputMismatchException();
			}
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	public boolean isSpaceChar(int c) {
		if (filter != null)
			return filter.isSpaceChar(c);
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

	public String next() {
		return readString();
	}

	public interface SpaceCharFilter {
		public boolean isSpaceChar(int ch);
	}
}


import java.util.*;
public class Main{
     public static void main(String ... string){
          Scanner sc = new Scanner(System.in);
          int t = sc.nextInt();
          while(t-- > 0){
               int n = sc.nextInt();
               int k = sc.nextInt();
               System.out.println((n-1)/(k-1));
          }
     }
}


import java.util.*;
public class Main{
     public static void main(String ... string){
          Scanner sc = new Scanner(System.in);
          int t = sc.nextInt();
          while(t-- > 0){
               int n = sc.nextInt();
               int k = sc.nextInt();
               int need = (k-1)/(n-1);
               System.out.println(need + k);
          }
     }
}


import java.util.*;
import java.io.*;

public class Main {

	public static void main(String[] args) {
		InputReader in = new InputReader(System.in);
	    int t = in.readInt();
	    while(t-- > 0) {
	    int n = in.readInt();
	    int k = in.readInt();
	    int temp = 1;
	    if(n == 2 && k == 1) {
	    	System.out.println(1);
	    	continue;
	    }
	    for(int i = 1; true; i++) {
	    	temp = i*n;
	    	k -= n-1;
	    	if(k < n) {
	    		System.out.println(temp + k);
	    		break;
	    	}
	      }
	   }
	}
}

class InputReader {

	private InputStream stream;
	private byte[] buf = new byte[1024];
	private int curChar;
	private int numChars;
	private SpaceCharFilter filter;

	public InputReader(InputStream stream) {
		this.stream = stream;
	}

	public int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

	public int readInt() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	public String readString() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

	public long readLong() {
		int c = read();
		while (isSpaceChar(c)) {
			c = read();
		}
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		long res = 0;
		do {
			if (c < '0' || c > '9') {
				throw new InputMismatchException();
			}
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	public boolean isSpaceChar(int c) {
		if (filter != null)
			return filter.isSpaceChar(c);
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

	public String next() {
		return readString();
	}

	public interface SpaceCharFilter {
		public boolean isSpaceChar(int ch);
	}
}


import java.util.*;
public class Main{
     public static void main(String ... string){
          Scanner sc = new Scanner(System.in);
          int t = sc.nextInt();
          while(t-- > 0){
               int n = in.readInt();
               int k = in.readInt();
               System.out.println((n-l)/(k-1));
          }
     }
}


import java.util.*;
public class Main{
     public static void main(String ... string){
          Scanner sc = new Scanner(System.in);
          int t = sc.nextInt();
          while(t-- > 0){
               int n = sc.nextInt();
               int k = sc.nextInt();
               int need = (n-1)/(k-1);
               System.out.println(need + k);
          }
     }
}


import java.util.*;
public class Main{
     public static void main(String ... string){
          Scanner sc = new Scanner(System.in);
          int t = sc.nextInt();
          while(t-- > 0){
               int n = sc.nextInt();
               int k = sc.nextInt();
               int need = k/n-1;
               System.out.println(need + k);
          }
     }
}


import java.io.*;
import java.util.StringTokenizer;

public class Solution {

    public static BufferedWriter bw;
    public static FastReader sc;

    public static void main(String[] args) throws Exception {
        sc = new FastReader();
        bw = new BufferedWriter(new OutputStreamWriter(System.out));
        int t = sc.nextInt();
        while (t > 0) {
            t--;
            int k = sc.nextInt();
            int n = sc.nextInt();
            long ans = solve(k, n);
            bw.write(ans + "\n");
        }
        bw.close();
    }

    private static long solve(int k, int n) {
        long ans = n;
        long prev = 0;
        while (true) {
            long q2 = ans / k;
            long q1 = prev / k;
            if (q1 == q2)
                return ans;

            prev = ans;
            ans += (q2 - q1);
        }
    }

}

class FastReader {
    BufferedReader br;
    StringTokenizer st;

    public FastReader() {
        br= new BufferedReader(new InputStreamReader(System.in));

    }

    public String next() {
        if (st == null || !st.hasMoreTokens()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {

            }
        }
        return st.nextToken();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public long nextLong() {
        return Long.parseLong(next());
    }
}


import java.io.*;
import java.util.StringTokenizer;

public class Solution {
    public static BufferedWriter bw;
    public static FastReader sc;

    public static void main(String[] args) throws Exception {
        sc = new FastReader();
        bw = new BufferedWriter(new OutputStreamWriter(System.out));
        int t = sc.nextInt();
        while (t > 0) {
            t--;
            int k = sc.nextInt();
            int n = sc.nextInt();
            long ans = solve(k, n);
            bw.write(ans + "\n");
        }
        bw.close();
    }

    private static long solve(int k, int n) {
        long ans = n;
        long prev = 0;
        long q1 = prev / k;
        while (true) {
            long q2 = ans / k;
            if (q1 == q2)
                return ans;
            prev = ans;
            q1=q2;
            ans += (q2 - q1);
        }
    }

}

class FastReader {
    BufferedReader br;
    StringTokenizer st;

    public FastReader() {
        br= new BufferedReader(new InputStreamReader(System.in));
    }

    public String next() {
        if (st == null || !st.hasMoreTokens()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {

            }
        }
        return st.nextToken();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public long nextLong() {
        return Long.parseLong(next());
    }
}


import java.util.Scanner;

public class Controller {
    public static void main(String[] args)
    {
        int t;
        int count=0;
        int rescount=0;
        Scanner c = new Scanner(System.in) ;
        t = c.nextInt();
        int[] arr =  new int[t*2];
        int[] res =  new int[t+1];
        //initialize the input array
        for (int i=0;i<t*2;i++)
        {
            arr[i]= c.nextInt();
        }
        //for every test number of divisibility
        for(int i =0;i<t*2;i+=2)
        {
            //loop until you find the k-th(j at the end of the loop)
            for (int j=0;count<arr[i+1];j++)
            {
                //every time you find a number divisible count++
                if (j%arr[i]!=0&&j!=0)
                {
                    count++;

                }
                //when the count reaches the wanted k-th add it to the array
                if (count==arr[i+1])
                {
                    res[rescount]=j;
                    rescount++;

                }

            }
            count=0;
        }
        //output the result
        for (int i=0;i<t;i++)
        {
            System.out.println(res[i]);
        }

    }
}


import java.util.Scanner;

public class Controller {
    public static void main(String[] args)
    {
        int t;
        int count=0;
        int rescount=0;
        Scanner c = new Scanner(System.in) ;
        t = c.nextInt();
        int[] arr =  new int[t*2];
        int[] res =  new int[t+1];
        //initialize the input array
        for (int i=0;i<t*2;i++)
        {
            arr[i]= c.nextInt();
        }
        //for every test number of divisibility
        for(int i =0;i<t*2;i+=2)
        {
            //in case k>n should start counting from k
           if (arr[i]<arr[i+1])
           {
               if (arr[i]%2==0)
               {
                   count= ( arr[i+1]-arr[i+1]%arr[i] ) - ( (arr[i+1]- (arr[i+1]%arr[i])) /arr[i] )+(arr[i+1]%arr[i]);

                   //loop until you find the k-th(j at the end of the loop)
                   for (int j=arr[i+1]+1;count<arr[i+1];j+=2)
                   {
                       //every time you find a number divisible count++
                       if (j%arr[i]!=0&&j!=0)
                       {

                           count++;

                       }
                       //when the count reaches the wanted k-th add it to the array
                       if (count==arr[i+1])
                       {
                           res[rescount]=j;
                           rescount++;

                       }

                   }
               }
               }
               else
                   {
                       count= ( arr[i+1]-arr[i+1]%arr[i] ) - ( (arr[i+1]- (arr[i+1]%arr[i])) /arr[i] )+(arr[i+1]%arr[i]);

                       //loop until you find the k-th(j at the end of the loop)
                       for (int j=arr[i+1]+1;count<arr[i+1];j++)
                       {
                           //every time you find a number divisible count++
                           if (j%arr[i]!=0&&j!=0)
                           {

                               count++;

                           }
                           //when the count reaches the wanted k-th add it to the array
                           if (count==arr[i+1])
                           {
                               res[rescount]=j;
                               rescount++;

                           }

                       }
                   }

               count=0;
            //in case k<n the the number is k
            if (arr[i]>arr[i+1])
            {
                res[rescount]=arr[i+1];
                rescount++;
            }
            //in case k=n the the number is k+1
            if (arr[i]==arr[i+1])
            {
                res[rescount]=arr[i+1]+1;
                rescount++;
            }

        }
        //output the result
        for (int i=0;i<t;i++)
        {
            System.out.println(res[i]);
        }

    }
}


import java.util.Scanner;

public class Controller {
    public static void main(String[] args)
    {
        int t;
        int count=0;
        int rescount=0;
        Scanner c = new Scanner(System.in) ;
        t = c.nextInt();
        int[] arr =  new int[t*2];
        int[] res =  new int[t+1];
        //initialize the input array
        for (int i=0;i<t*2;i++)
        {
            arr[i]= c.nextInt();
        }
        //for every test number of divisibility
        for(int i =0;i<t*2;i+=2)
        {
            //in case k>n should start counting from k
           if (arr[i]<arr[i+1])
           {
               if (arr[i]%2==0)
               {
                   count= ( arr[i+1]-arr[i+1]%arr[i] ) - ( (arr[i+1]- (arr[i+1]%arr[i])) /arr[i] )+(arr[i+1]%arr[i]);
                   System.out.println(count+"t");
                   //loop until you find the k-th(j at the end of the loop)
                   for (int j=arr[i+1]+1;count<arr[i+1];j+=2)
                   {
                       //every time you find a number divisible count++
                       if (j%arr[i]!=0&&j!=0)
                       {

                           count++;

                       }
                       //when the count reaches the wanted k-th add it to the array
                       if (count==arr[i+1])
                       {
                           res[rescount]=j;
                           rescount++;

                       }

                   }
               }
               }
               else
                   {
                       count= ( arr[i+1]-arr[i+1]%arr[i] ) - ( (arr[i+1]- (arr[i+1]%arr[i])) /arr[i] )+(arr[i+1]%arr[i]);
                       System.out.println(count+"t");
                       //loop until you find the k-th(j at the end of the loop)
                       for (int j=arr[i+1]+1;count<arr[i+1];j++)
                       {
                           //every time you find a number divisible count++
                           if (j%arr[i]!=0&&j!=0)
                           {

                               count++;

                           }
                           //when the count reaches the wanted k-th add it to the array
                           if (count==arr[i+1])
                           {
                               res[rescount]=j;
                               rescount++;

                           }

                       }
                   }

               count=0;
            //in case k<n the the number is k
            if (arr[i]>arr[i+1])
            {
                res[rescount]=arr[i+1];
                rescount++;
            }
            //in case k=n the the number is k+1
            if (arr[i]==arr[i+1])
            {
                res[rescount]=arr[i+1]+1;
                rescount++;
            }

        }
        //output the result
        for (int i=0;i<t;i++)
        {
            System.out.println(res[i]);
        }

    }
}


import java.util.Scanner;

public class Main {
    public static void main(String[] args)
    {
        int t;
        int k_th=0;
        int rescount=0;
        Scanner c = new Scanner(System.in) ;
        t = c.nextInt();
        int[] arr =  new int[t*2];
        int[] res =  new int[t+1];
        //initialize the input array
        for (int i=0;i<t*2;i++)
        {
            arr[i]= c.nextInt();
        }
        //for every test number of divisibility
        for(int i =0;i<t*2;i+=2)
        {
            long last = 1999999999;
            long first = 1;
            long mid= (last+first)/2;
            long midpos;
            //in case k>n should start counting from k
            if (arr[i]<arr[i+1])
            {
               for (int f=0;mid<last&&mid>first;f++)
               {

                midpos =  ( mid-mid%arr[i] ) - ( (mid- (mid%arr[i])) /arr[i] )+(mid%arr[i]);
                if (midpos<arr[i+1])
                {
                    first= mid ;
                    mid = (first+last)/2;

                }
                if (midpos>arr[i+1])
                {
                    last= mid ;
                    mid = (first+last)/2;

                }
                if (midpos==arr[i+1])
                {
                    break;
                }

               }
               if(mid%arr[i]==0){mid++;}
                res[rescount]=(int)mid;
                rescount++;

            }
            //in case k<n the the number is k
            if (arr[i]>arr[i+1])
            {
                res[rescount]=arr[i+1];
                rescount++;
            }
            //in case k=n the the number is k+1
            if (arr[i]==arr[i+1])
            {
                res[rescount]=arr[i+1]+1;
                rescount++;
            }

        }
        //output the result
        for (int i=0;i<t;i++)
        {
            System.out.println(res[i]);
        }

    }
}


import java.util.Scanner;

public class Controller {
    public static void main(String[] args)
    {
        int t;
        int count=0;
        int rescount=0;
        Scanner c = new Scanner(System.in) ;
        t = c.nextInt();
        int[] arr =  new int[t*2];
        int[] res =  new int[t+1];
        //initialize the input array
        for (int i=0;i<t*2;i++)
        {
            arr[i]= c.nextInt();
        }
        //for every test number of divisibility
        for(int i =0;i<t*2;i+=2)
        {
            //in case k>n should start counting from k
           if (arr[i]<arr[i+1])
           {
               count= ( arr[i+1]-arr[i+1]%arr[i] ) - ( (arr[i+1]- (arr[i+1]%arr[i])) /arr[i] )+(arr[i+1]%arr[i]);

               //loop until you find the k-th(j at the end of the loop)
               for (int j=arr[i+1]+1;count<arr[i+1];j++)
               {
                   //every time you find a number divisible count++
                   if (j%arr[i]!=0&&j!=0)
                   {

                       count++;

                   }
                   //when the count reaches the wanted k-th add it to the array
                   if (count==arr[i+1])
                   {
                       res[rescount]=j;
                       rescount++;

                   }

               }
           } count=0;
            //in case k<n the the number is k
            if (arr[i]>arr[i+1])
            {
                res[rescount]=arr[i+1];
                rescount++;
            }
            //in case k=n the the number is k+1
            if (arr[i]==arr[i+1])
            {
                res[rescount]=arr[i+1]+1;
                rescount++;
            }

        }
        //output the result
        for (int i=0;i<t;i++)
        {
            System.out.println(res[i]);
        }

    }
}


import java.util.Scanner;

public class Main {
    public static void main(String[] args)
    {
        int t;
        int k_th=0;
        int rescount=0;
        Scanner c = new Scanner(System.in) ;
        t = c.nextInt();
        int[] arr =  new int[t*2];
        int[] res =  new int[t+1];
        //initialize the input array
        for (int i=0;i<t*2;i++)
        {
            arr[i]= c.nextInt();
        }
        //for every test number of divisibility
        for(int i =0;i<t*2;i+=2)
        {
            long last = 1999999999;
            long first = 1;
            long mid= (last+first)/2;
            long midpos=0;
            //in case k>n should start counting from k
            if (arr[i]<arr[i+1])
            {
               for (int f=0;mid<=last&&mid>=first;f++)
               {
                   System.out.println(first+"<>"+last);
                   System.out.println(mid+"<<>>"+midpos);

                midpos =  ( mid-mid%arr[i] ) - ( (mid- (mid%arr[i])) /arr[i] )+(mid%arr[i]);
                if (midpos<arr[i+1])
                {
                    first= mid ;
                    mid = (first+last)/2;

                }
                if (midpos>arr[i+1])
                {
                    last= mid ;
                    mid = (first+last)/2;

                }
                if (midpos==arr[i+1])
                {
                    break;
                }

               }
               if(mid%arr[i]==0){mid--;}
                res[rescount]=(int)mid;
                rescount++;

            }
            //in case k<n the the number is k
            if (arr[i]>arr[i+1])
            {
                res[rescount]=arr[i+1];
                rescount++;
            }
            //in case k=n the the number is k+1
            if (arr[i]==arr[i+1])
            {
                res[rescount]=arr[i+1]+1;
                rescount++;
            }

        }
        //output the result
        for (int i=0;i<t;i++)
        {
            System.out.println(res[i]);
        }

    }
}


import java.util.Scanner;

public class Main {
    public static void main(String[] args)
    {
        int t;
        int k_th=0;
        int rescount=0;
        Scanner c = new Scanner(System.in) ;
        t = c.nextInt();
        int[] arr =  new int[t*2];
        int[] res =  new int[t+1];
        //initialize the input array
        for (int i=0;i<t*2;i++)
        {
            arr[i]= c.nextInt();
        }
        //for every test number of divisibility
        for(int i =0;i<t*2;i+=2)
        {
            long last = 1999999999;
            long first = 1;
            long mid= (last+first)/2;
            long midpos=0;
            long lastpos=( last-last%arr[i] ) - ( (last- (last%arr[i])) /arr[i] )+(last%arr[i]);
            long firstpos=( first-first%arr[i] ) - ( (first- (first%arr[i])) /arr[i] )+(first%arr[i]);
            //in case k>n should start counting from k
            if (arr[i]<arr[i+1])
            {
                //check edges
                if (lastpos==arr[i+1])
                {
                    mid=last;
                }
                else if(firstpos==arr[i+1])
                 {
                     mid=first;
                 }
                else
                    {

               for (int f=0;mid<=last&&mid>=first;f++)
               {

                midpos =  ( mid-mid%arr[i] ) - ( (mid- (mid%arr[i])) /arr[i] )+(mid%arr[i]);
                if (midpos<arr[i+1])
                {
                    first= mid ;
                    mid = (first+last)/2;

                }
                if (midpos>arr[i+1])
                {
                    last= mid ;
                    mid = (first+last)/2;

                }
                if (midpos==arr[i+1])
                {
                    break;
                }

               }
                    }
               if(mid%arr[i]==0){mid--;}
                res[rescount]=(int)mid;
                rescount++;

            }
            //in case k<n the the number is k
            if (arr[i]>arr[i+1])
            {
                res[rescount]=arr[i+1];
                rescount++;
            }
            //in case k=n the the number is k+1
            if (arr[i]==arr[i+1])
            {
                res[rescount]=arr[i+1]+1;
                rescount++;
            }

        }
        //output the result
        for (int i=0;i<t;i++)
        {
            System.out.println(res[i]);
        }

    }
}


import java.util.Scanner;

public class Main {
    public static void main(String[] args)
    {
        int t;
        int k_th=0;
        int rescount=0;
        Scanner c = new Scanner(System.in) ;
        t = c.nextInt();
        int[] arr =  new int[t*2];
        int[] res =  new int[t+1];
        //initialize the input array
        for (int i=0;i<t*2;i++)
        {
            arr[i]= c.nextInt();
        }
        //for every test number of divisibility
        for(int i =0;i<t*2;i+=2)
        {
            long last = 1999999999;
            long first = 1;
            long mid= (last+first)/2;
            long midpos=0;
            long lastpos=( last-last%arr[i] ) - ( (last- (last%arr[i])) /arr[i] )+(last%arr[i]);
            long firstpos=( first-first%arr[i] ) - ( (first- (first%arr[i])) /arr[i] )+(first%arr[i]);
            //in case k>n should start counting from k
            if (arr[i]<arr[i+1])
            {
                //check edges
                if (lastpos==arr[i+1])
                {
                    mid=last;
                }
                else if(firstpos==arr[i+1])
                 {
                     mid=first;
                 }
                else
                    {

               for (int f=0;mid<=last&&mid>=first;f++)
               {
                   System.out.println(first+"<>"+last);
                   System.out.println(mid+"<<>>"+midpos);

                midpos =  ( mid-mid%arr[i] ) - ( (mid- (mid%arr[i])) /arr[i] )+(mid%arr[i]);
                if (midpos<arr[i+1])
                {
                    first= mid ;
                    mid = (first+last)/2;

                }
                if (midpos>arr[i+1])
                {
                    last= mid ;
                    mid = (first+last)/2;

                }
                if (midpos==arr[i+1])
                {
                    break;
                }

               }
                    }
               if(mid%arr[i]==0){mid--;}
                res[rescount]=(int)mid;
                rescount++;

            }
            //in case k<n the the number is k
            if (arr[i]>arr[i+1])
            {
                res[rescount]=arr[i+1];
                rescount++;
            }
            //in case k=n the the number is k+1
            if (arr[i]==arr[i+1])
            {
                res[rescount]=arr[i+1]+1;
                rescount++;
            }

        }
        //output the result
        for (int i=0;i<t;i++)
        {
            System.out.println(res[i]);
        }

    }
}


import java.util.Scanner;

/**
 * Created by rkarumuru on 5/9/20
 **/
public class KthNotDivByN {

  private static Scanner scanner = new Scanner(System.in);

  public static void main(String[] args) {

    int t = getInt();
    for (int i = 0; i < t; i++) {
      solve();
    }

  }

  private static void solve() {
    long n = scanner.nextInt();
    long k = getInt();

    long l = 1;
    long h = 2 * k;

    while (true) {
      long x = (l + h)/2;

      if (x == k + x/n) {
        System.out.println(x);
        break;
      } else if ((x > k + x/n)){
        h = x -1;
      } else {
        l = x + 1;
      }

    }
  }

  public static int getInt() {
    return Integer.parseInt(scanner.nextLine().trim());
  }

  public static String getString() {
    return scanner.nextLine().trim();
  }

  public static double getDouble() {
    return Double.parseDouble(scanner.nextLine());
  }

  public static long getlong() {
    return Long.parseLong(scanner.nextLine());
  }
}


import java.util.Scanner;

/**
 * Created by rkarumuru on 5/9/20
 **/
public class KthNotDivByN {

  private static Scanner scanner = new Scanner(System.in);

  public static void main(String[] args) {

    int t = getInt();
    for (int i = 0; i < t; i++) {
      solve();
    }

  }

  private static void solve() {
    long n = scanner.nextInt();
    long k = getInt();

    long l = 1;
    long h = 2 * k;
    long x = 0;
    while (true) {
      x = (l + h)/2;

      if (x == k + x/n) {
        break;
      } else if ((x > k + x/n)){
        h = x -1;
      } else {
        l = x + 1;
      }
    }

    for (long i = 1; i < 10; i++) {
      if (x-i == k + (x-i)/n) {
        x = x-i;
      }
    }
    System.out.println(x);
  }

  public static int getInt() {
    return Integer.parseInt(scanner.nextLine().trim());
  }

  public static String getString() {
    return scanner.nextLine().trim();
  }

  public static double getDouble() {
    return Double.parseDouble(scanner.nextLine());
  }

  public static long getlong() {
    return Long.parseLong(scanner.nextLine());
  }
}