#include <bits/stdc++.h>
using namespace std;

#define int long long /////////////all are the same ( maybe i mixed between these alot !! )

signed main() {
	
	int tt=1;
	cin>>tt;
	
	for(int i =1 ;i <= tt; i++){
		
		long long a,b;cin>>a>>b;
		
		
		
		long long s = a + b;
		long long new_b = -1;
		
		
		
		if ((b & s) == b) {
		    new_b = b; // b is already a submask of s — zero cost, optimal
		} else {
		    // divergence-point search loop ...
		    
		    
			
			for (int bit = 0; bit <= 30; bit++) {
			
			    long long val = 1LL << bit;
			
			    // Candidate divergence point requires: b has 0 here (so new_b
			    // can have 1 and become bigger), and s has 1 here (new_b must
			    // be a submask of s).
			    if ((b & val) || !(s & val))
			        continue;
			
			    bool possible = true;
			
			    // Above the divergence point, new_b must equal b exactly.
			    // So every 1-bit of b up there must also exist in s.
			    for (int j = bit + 1; j <= 30; j++) {
			        long long higher = 1LL << j;
			        if ((b & higher) && !(s & higher)) {
			            possible = false; // can't reproduce b's prefix using s's bits
			            break;
			        }
			    }
			
			    if (possible) {
			        // Build new_b: same prefix as b above this bit, 1 at this
			        // bit, 0 below (smallest choice — lower bits aren't needed).
			        new_b = (b >> (bit + 1)) << (bit + 1);
			        new_b |= val;
			        break; // lowest achievable divergence point = smallest new_b
			    }
			}
		    
		}
		
		
		
		
		// No divergence point found => b is already a submask of s.
		if (new_b == -1) {
		    new_b = b;
		}
		
		cout << s << ' ' << new_b - b << '\n';
		
		
		
	}
	
	
	
}