Reverse Engineering

No attempts yetTime limit1sMemory limit128 MB

Problem

The police recently intercepted a fragment of source code that the anarchist groups MCA and MBI were passing to each other. The fragment is below. The anarchists write strictly in C, so the original is C, and a transcription into Pascal comes with it for readability.

int main()
{ int u,v,k,t ;
  scanf("%d %d",&u,&v) ;
  for (k=0;!(u%2)&&!(v%2);k++)
    { u/=2 ; v/=2 ; }
  if (u%2) t=-v ; 
  else t=u/2 ;
  while(t) {
    while(!(t%2)) t/=2 ;
    if (t>0) u=t ; else v=-t ;
    t=u-v ; 
  }
  while(k-->0) u*=2 ; 
  printf("%d\n",u) ;
  return 0 ;
}
program zahada;
var u,v,k,t:integer;
begin
  readln(u,v); k:=0;
  while(u mod 2=0)and(v mod 2=0) do
    begin u:=u div 2; v:=v div 2; k:=k+1; end;
  if(u mod 2<>0) then t:=-v
  else t:=u div 2;
  while(t<>0) do begin
    while(t mod 2=0) do t:=t div 2;
    if(t>0) then u:=t else v:=-t;
    t:=u-v;
  end;
  while(k>0) do begin u:=u*2; k:=k-1; end;
  writeln(u:1);
end.

At a glance the program reads two numbers from the input and computes some result. Nobody has cracked the computation itself yet, so the exact link between input and output is unknown. Call the function the program implements ff. Its domain is the set of positive integers. If the integers aa and bb are given to the program, then f(a,b)f(a, b) is the value it prints. If the program does not halt or ends with an error, f(a,b)f(a, b) is undefined for that input. Watching the function closely needs an inverse: find two numbers aa and bb for which f(a,b)f(a, b) equals a value fixed in advance.

Input

The first line contains a positive integer ZZ, followed by ZZ assignments in order. Each assignment is a single line with two integers NN and MM separated by a space. 0<N,M10000000 < N, M \le 1000000.

Output

For each assignment print one line with two numbers UU and VV separated by a space. The two numbers must satisfy both f(U,V)=Mf(U, V) = M and 1V<U<N1 \le V < U < N. If several pairs satisfy the conditions, print the one with the largest UU. If several solutions share that largest UU, print the one among them with the largest VV. If no pair satisfies the conditions, print Reseni neexistuje. on that line.