import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintWriter; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(br.readLine()); PrintWriter pw = new PrintWriter(System.out); for (int z = 0; z < t; z++) { String[] sa = br.readLine().split(" "); long x = Long.parseLong(sa[0]); int y = Integer.parseInt(sa[1]); int m = 0; for (int i = y + 1; i <= 60; i++) { if ((x >> i & 1) == 0) { m = i; break; } } pw.println((1 << m) - 1); } pw.flush(); br.close(); } }