#include <bits/stdc++.h>
#include <string>
#include <math.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rev_rep(i, n) for(int i = n - 1; i > 0; i--)
#define pb push_back
vector<int> arr;
string to_binary(int n){
string r = "";
while(n != 0){
r = (n % 2 == 0 ? "0" : "1") + r;
n /= 2;
}
return r;
}
int to_int(int n){
int response = 0;
int i = 0;
while(n){
response += (n % 10) * pow(2, i);
i++;
n /= 10;
}
return response;
}
void bin_concat(int x, int y){
string x_plus_y = to_binary(x) + to_binary(y);
string y_plus_x = to_binary(y) + to_binary(x);
cout << to_int(stoi(x_plus_y)) - to_int(stoi(y_plus_x));
}
void solve(){
int min_b = *min_element(arr.begin(), arr.end());
int max_b = *max_element(arr.begin(), arr.end());
bin_concat(min_b, max_b);
}
int main() {
ios_base::sync_with_stdio (false);
cin.tie (NULL);
cout.tie (NULL);
int t, n;
cin >> t;
while (t--) {
cin >> n;
int temp;
rep(i, n) {
cin >> temp;
arr.pb(temp);
}
solve();
cout << "\n";
arr.clear();
}
}
link of submission: CodeChef: Practical coding for everyone
problem: BINFUN Problem - CodeChef