using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static int NN => int.Parse(ReadLine()); static long[] NList => ReadLine().Split().Select(long.Parse).ToArray(); public static void Main() { Solve(); } static void Solve() { var t = NN; var ans = new long[t]; for (var u = 0; u < t; ++u) { var c = NList; var (x, y) = (c[0], (int)c[1]); var max = y; while ((x & (1 << max + 1)) != 0) ++max; ans[u] = (1 << max + 1) - 1; } WriteLine(string.Join("\n", ans)); } }