description: Alice gave Bob two integers a and b (a > 0 and b ≥ 0). Being a curious boy, Bob wrote down an array of non-negative integers with \operatorname{MEX} value of all elements equal to a and \operatorname{XOR} value of all elements equal to b.
  
  What is the shortest possible length of the array Bob wrote?
  
  Recall that the \operatorname{MEX} (Minimum EXcluded) of an array is the minimum non-negative integer that does not belong to the array and the \operatorname{XOR} of an array is the [bitwise XOR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR) of all the elements of the array.
  
  Input
  
  The input consists of multiple test cases. The first line contains an integer t (1 ≤ t ≤ 5 ⋅ 10^4) — the number of test cases. The description of the test cases follows.
  
  The only line of each test case contains two integers a and b (1 ≤ a ≤ 3 ⋅ 10^5; 0 ≤ b ≤ 3 ⋅ 10^5) — the \operatorname{MEX} and \operatorname{XOR} of the array, respectively.
  
  Output
  
  For each test case, output one (positive) integer — the length of the shortest array with \operatorname{MEX} a and \operatorname{XOR} b. We can show that such an array always exists.
  
  Example
  
  Input
  
  
  5
  1 1
  2 1
  2 0
  1 10000
  2 10000
  
  
  Output
  
  
  3
  2
  3
  2
  3
  
  Note
  
  In the first test case, one of the shortest arrays with \operatorname{MEX} 1 and \operatorname{XOR} 1 is [0, 2020, 2021].
  
  In the second test case, one of the shortest arrays with \operatorname{MEX} 2 and \operatorname{XOR} 1 is [0, 1].
  
  It can be shown that these arrays are the shortest arrays possible.
solution: import java.util.Comparator;
  import java.util.*;
  
  /**
   * @author Yuxuan Wu
   */
  public class Main {
      public static final int RANGE = 1000000;
      static int MAX = Integer.MAX_VALUE;
      static int MIN = Integer.MIN_VALUE;
      static int MODULO = 1000000007;
      static Scanner sc = new Scanner(System.in);
  
      static int multi = 1;
  
      private static void solve() {
          int mex = sc.nextInt();
          int xor = sc.nextInt();
          int ans = 0;
          if((mex-1) % 4 == 0){
              ans = mex-1;
          }else if((mex-1) % 4 == 1){
              ans = 1;
          }
          else if((mex-1) % 4 == 2){
              ans = mex;
          }
          if(ans == xor){
              System.out.println(mex);
          }
          else{
              int c = ans ^ xor;
              if(c == mex){
                  mex++;
              }
              System.out.println(mex+1);
          }
      }
      
      public static void main(String[] args) {
          if(multi == 0){
              solve();
          }
          else {
              int T = sc.nextInt();
              for(int t = 1; t <= T; ++t){
                  solve();
              }
          }
      }
  
      /**
       * 阶乘
       */
      private static int factorial(int n) {
          if(n == 0 || n == 1){
              return n;
          }
          return factorial(n-1) * n;
      }
  
      /**
       * 返回最大公约数
       * 时间复杂度 O(Log min(n1, n2))
       */
      public static long gcd(long n1, long n2) {
          if (n2 == 0) {
              return n1;
          }
          return gcd(n2, n1 % n2);
      }
  
      /**
       * 返回该数的位数
       */
      public static int getDigit(long num){
          int ans = 0;
          while(num > 0){
              ans++;
              num /= 10;
          }
          return ans;
      }
  
      /**
       * 返回该数各位之和
       */
      public static int digitSum(long num) {
          int ans = 0;
          while (num > 0) {
              ans += num % 10;
              num /= 10;
          }
          return ans;
      }
  
      /**
       * 判断是否为回文串
       */
      public static boolean palindrome(String s) {
          int n = s.length();
          for(int i = 0; i < n; i++) {
              if(s.charAt(i) != s.charAt(n - i - 1)) {
                  return false;
              }
          }
          return true;
      }
  
      /**
       * 判断是否为完全平方数
       */
      public static boolean isSquare(int num) {
          double a = 0;
          try {
              a = Math.sqrt(num);
          } catch (Exception e) {
              return false;
          }
          int b = (int) a;
          return a - b == 0;
      }
  
      public static class Pairs<K, V> implements Comparable<Pairs> {
          private K key;
          private V value;
  
          public K getKey() { return key; }
          public V getValue() { return value; }
          public void setKey(K key) {
              this.key = key;
          }
          public void setValue(V value) {
              this.value = value;
          }
          public Pairs( K key,  V value) {
              this.key = key;
              this.value = value;
          }
  
          @Override
          public String toString() {
              return key + " = " + value;
          }
  
          @Override
          public boolean equals(Object o) {
              if (this == o) {
                  return true;
              }
              if (o == null || getClass() != o.getClass()) {
                  return false;
              }
              Pairs<?, ?> pairs = (Pairs<?, ?>) o;
              return Objects.equals(key, pairs.key) &&
                      Objects.equals(value, pairs.value);
          }
  
          @Override
          public int hashCode() {
              return Objects.hash(key, value);
          }
  
          @Override
          public int compareTo(Pairs o) {
              return 0;
          }
      }
  
      static class CompInt implements Comparator<Pairs>{
          @Override
          public int compare(Pairs o1, Pairs o2) {
              if(o1.key instanceof  Integer&&o2.key instanceof  Integer){
                  if((int)o1.key>(int)o2.key){
                      return 1;
                  }else{
                      return -1;
                  }
              }
              return 0;
          }
      }
  
      static class CompLong implements Comparator<Pairs>{
          @Override
          public int compare(Pairs o1, Pairs o2) {
              return Long.compare((long)o1.key, (long)o2.key);
          }
      }
  
      static class CompDouble implements Comparator<Pairs>{
          @Override
          public int compare(Pairs o1, Pairs o2) {
              if(o1.key instanceof  Double && o2.key instanceof Double){
                  return Double.compare((double) o1.key, (double) o2.key);
              }
              return 0;
          }
      }
  
      /*
      static class Reader {
          final private int BUFFER_SIZE = 1 << 16;
          private DataInputStream din;
          private byte[] buffer;
          private int bufferPointer, bytesRead;
  
          public Reader()
          {
              din = new DataInputStream(System.in);
              buffer = new byte[BUFFER_SIZE];
              bufferPointer = bytesRead = 0;
          }
  
          public Reader(String file_name) throws IOException
          {
              din = new DataInputStream(
                      new FileInputStream(file_name));
              buffer = new byte[BUFFER_SIZE];
              bufferPointer = bytesRead = 0;
          }
  
          public String readLine() throws IOException
          {
              byte[] buf = new byte[64]; // line length
              int cnt = 0, c;
              while ((c = read()) != -1) {
                  if (c == '\n') {
                      if (cnt != 0) {
                          break;
                      }
                      else {
                          continue;
                      }
                  }
                  buf[cnt++] = (byte)c;
              }
              return new String(buf, 0, cnt);
          }
  
          public int nextInt() throws IOException
          {
              int ret = 0;
              byte c = read();
              while (c <= ' ') {
                  c = read();
              }
              boolean neg = (c == '-');
              if (neg) {
                  c = read();
              }
              do {
                  ret = ret * 10 + c - '0';
              } while ((c = read()) >= '0' && c <= '9');
  
              if (neg) {
                  return -ret;
              }
              return ret;
          }
  
          public long nextLong() throws IOException
          {
              long ret = 0;
              byte c = read();
              while (c <= ' ') {
                  c = read();
              }
              boolean neg = (c == '-');
              if (neg) {
                  c = read();
              }
              do {
                  ret = ret * 10 + c - '0';
              } while ((c = read()) >= '0' && c <= '9');
              if (neg) {
                  return -ret;
              }
              return ret;
          }
  
          public double nextDouble() throws IOException
          {
              double ret = 0, div = 1;
              byte c = read();
              while (c <= ' ') {
                  c = read();
              }
              boolean neg = (c == '-');
              if (neg) {
                  c = read();
              }
  
              do {
                  ret = ret * 10 + c - '0';
              } while ((c = read()) >= '0' && c <= '9');
  
              if (c == '.') {
                  while ((c = read()) >= '0' && c <= '9') {
                      ret += (c - '0') / (div *= 10);
                  }
              }
  
              if (neg) {
                  return -ret;
              }
              return ret;
          }
  
          private void fillBuffer() throws IOException
          {
              bytesRead = din.read(buffer, bufferPointer = 0,
                      BUFFER_SIZE);
              if (bytesRead == -1) {
                  buffer[0] = -1;
              }
          }
  
          private byte read() throws IOException
          {
              if (bufferPointer == bytesRead) {
                  fillBuffer();
              }
              return buffer[bufferPointer++];
          }
  
          public void close() throws IOException
          {
              if (din == null) {
                  return;
              }
              din.close();
          }
      }
  
       */
  }
  