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 f. Its domain is the set of positive integers. If the integers a and b are given to the program, then f(a,b) is the value it prints. If the program does not halt or ends with an error, f(a,b) is undefined for that input. Watching the function closely needs an inverse: find two numbers a and b for which f(a,b) equals a value fixed in advance.
The first line contains a positive integer Z, followed by Z assignments in order. Each assignment is a single line with two integers N and M separated by a space. 0<N,M≤1000000.
For each assignment print one line with two numbers U and V separated by a space. The two numbers must satisfy both f(U,V)=M and 1≤V<U<N. If several pairs satisfy the conditions, print the one with the largest U. If several solutions share that largest U, print the one among them with the largest V. If no pair satisfies the conditions, print Reseni neexistuje. on that line.