Under construction

Still being built. Things may change

Largest Common Vertex on a Rooted Tree

Interview

Time limit2sMemory limit512 MB

Summary
For two nodes in a complete binary tree numbered heap-style, find the deepest common ancestor k and print 10k.
Level

Easy3 of 10

Topics
Tree, Math, Bit manipulation
Solved
No attempts yet

Problem

A rooted tree has 1023 vertices. Vertex 1 is the root, and the two children of vertex vv are vertex 2v2v and vertex 2v+12v+1. Under this rule each natural number from 1 to 1023 is attached to exactly one vertex. Vertices numbered 512 to 1023 have no children. The top four levels look like this.

                1
        2               3
    4       5       6       7
  8   9   10  11  12  13  14  15

Let M(a,b)M(a, b) be the largest vertex number that lies on both the path from vertex 1 to vertex aa and the path from vertex 1 to vertex bb. For example, M(4,11)=2M(4, 11) = 2 and M(7,12)=3M(7, 12) = 3.

Given two natural numbers AA and BB, let M(A,B)=kM(A, B) = k. Write a program that computes 10k10k.

Input

The first line contains the number of test cases TT (1≤T≤500001 \le T \le 50000). Each of the next TT lines holds one test case: two integers AA and BB (1≤A,B≤10231 \le A, B \le 1023, A≠BA \ne B) separated by a single space.

Output

For each test case, print the value of 10k10k on its own line.

Examples2

  1. Example 1

    Input
    3
    33 79
    9 15
    1022 1023
    
    Expected output
    40
    10
    5110
    
  2. Example 2

    Input
    2
    4 11
    7 12
    
    Expected output
    20
    30