#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

static vector<vector<int>> color(3);

void find_posotions(int cur_ind,int another, int* positions) {
	while (color[0][cur_ind] > color[another][positions[0]] && positions[0] + 1 < color[another].size()) {
		++positions[0];
	}
	positions[1] = positions[0];
	if (positions[0] != 0) {
		--positions[0];
	}
	if (positions[1]+2 < color[another].size()) {
		positions[2] = positions[1] + 1;
	}
}

void solve() {
	vector<int> colors_count(3);
	int ind = 0;
	for (int& i : colors_count) {
		cin >> i;
		color[ind++].resize(i);
	}
	for (auto& v : color) {
		for (int& i : v) {
			cin >> i;
		}
		sort(v.begin(), v.end());
	}
	int64_t minimum = INT64_MAX;
	for (size_t v = 0; v < color.size(); ++v) {
		swap(color[0], color[v]);
		swap(colors_count[0], colors_count[v]);
		int f_positions[3];
		f_positions[0] = 0;
		f_positions[1] = 0;
		f_positions[2] = 0;
		int s_positions[3];
		s_positions[0] = 0;
		s_positions[1] = 0;
		s_positions[2] = 0;
		int f_ind(0), s_ind(0);
		for (size_t i = 0; i < color[0].size(); ++i) {
			find_posotions(i, 1, f_positions);
			find_posotions(i, 2, s_positions);
			for (size_t f = 0; f < 3; ++f) {
				for (size_t s = 0; s < 3; ++s) {
					int64_t result = (int64_t)(color[0][i] - color[1][f_positions[f]]) * (int64_t)(color[0][i] - color[1][f_positions[f]])
						+ (int64_t)(color[2][s_positions[s]] - color[1][f_positions[f]]) * (int64_t)(color[2][s_positions[s]] - color[1][f_positions[f]])
						+ (int64_t)(color[0][i] - color[2][s_positions[s]]) * (int64_t)(color[0][i] - color[2][s_positions[s]]);
					minimum = min(minimum, result);
				}
			}
		}
	}
	cout << minimum << '\n';
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

	int t;
	cin >> t;
	for (size_t i = 0; i < t; ++i) {
		solve();
	}
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
long long t,input;
inline long long cal(long long a, long long b, long long c) {
	return (a - b)*(a - b) + (b - c)*(b - c) + (c - a)*(c - a);
}
long long ans;
void solve(vector <long long>& a, vector <long long>& b, vector <long long>& c);
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(), cout.tie();
	cin >> t;
	while (t--) {
		int nr, ng, nb;
		cin >> nr >> ng >> nb;
		vector <long long> r, g, b;
		vector <pair<long long, long long> > all;
		while (nr--) {
			cin >> input;
			r.push_back(input);
		}

		while (ng--) {
			cin >> input;
			g.push_back(input);
		}

		while (nb--) {
			cin >> input;
			b.push_back(input);
		}
		sort(r.begin(), r.end());
		sort(g.begin(), g.end());
		sort(b.begin(), b.end());
		ans = 1e20;

		solve(r, g, b);
		solve(r, b, g);
		solve(g, r, b);
		solve(g, b, r);
		solve(b, r, g);
		solve(b, g, r);

		cout << ans << "\n";
	}
}
void solve(vector <long long>& a, vector <long long>& b, vector <long long>& c) {
	for (auto u : a) {
		int eg = upper_bound(b.begin(), b.end(), u) - b.begin();
		if (eg == 0) continue;
		eg--;
		auto ebb = lower_bound(c.begin(), c.end(), u);
		if (ebb == c.end()) continue;
		int eb = ebb - c.begin();
		ans = min(ans, cal(u, b[eg], c[eb]));
	}
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <iomanip>
#include <iomanip>
#include <string>
#include <set>
#include <utility>
#define sqr(a) (a)*(a)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair

using namespace std;

typedef pair<int,int> pii;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const int inf = 1e9;
const ll mod = 998244353;
const string imp = "IMPOSSIBLE";

void solve()
{
	int rn, gn, bn;
	cin >> rn >> gn >> bn;
	int n = rn + gn + bn;
	vector<pair<ll, int> > v(n);
	for(int i = 0; i < rn; i++)
	{
		cin >> v[i].first;
		v[i].second = 0;
	}
	for(int i = 0; i < gn; i++)
	{
		cin >> v[rn + i].first;
		v[rn + i].second = 1;
	}
	for(int i = 0; i < bn; i++)
	{
		cin >> v[rn + gn + i].first;
		v[rn + gn + i].second = 2;
	}
	sort(all(v));
	vector<ll> l(3, 0);
	int lst = -1;
	ll minans = 9e18;
	for(int i = 0; i < n; i++)
	{
		if(v[i].second == 0)
		{
			int j = i;
			while(j < n && v[j].second == 0)
				j++;
			if(j == n)
				break;
			if(v[j].second == lst || lst == -1)
			{
				l[0] = v[j-1].first;
				i = j-1;
				lst = 0;
				continue;
			}
			//cout << i << " " << l[0] << " " << l[1] << " " << l[2] << " " << lst << endl;
			if(lst == 1)
				l[2] = v[j].first;
			else
				l[1] = v[j].first;
			j--;
			int st = i;
			for(; st <= j; st++)
			{
				ll cur = sqr(l[1] - v[st].first) + sqr(l[2] - v[st].first) + sqr(l[1] - l[2]);
				minans = min(minans, cur);
			}
			l[0] = v[j].first;
			i = j;
			lst = 0;
			continue;
		}
		if(v[i].second == 1)
		{
			int j = i;
			while(j < n && v[j].second == 1)
				j++;
			if(j == n)
				break;
			if(v[j].second == lst || lst == -1)
			{
				l[1] = v[j-1].first;
				i = j-1;
				lst = 1;
				continue;
			}
			//cout << i << " " << l[0] << " " << l[1] << " " << l[2] << " " << lst << endl;
			if(lst == 0)
				l[2] = v[j].first;
			else
				l[0] = v[j].first;
			j--;
			int st = i;
			for(; st <= j; st++)
			{
				ll cur = sqr(l[0] - v[st].first) + sqr(l[2] - v[st].first) + sqr(l[0] - l[2]);
				minans = min(minans, cur);
			}
			l[1] = v[j].first;
			i = j;
			lst = 1;
			continue;
		}
		if(v[i].second == 2)
		{
			int j = i;
			while(j < n && v[j].second == 2)
				j++;
			if(j == n)
				break;
			if(v[j].second == lst || lst == -1)
			{
				l[2] = v[j-1].first;
				i = j-1;
				lst = 2;
				continue;
			}
			//cout << i << " " << l[0] << " " << l[1] << " " << l[2] << " " << lst << endl;
			if(lst == 1)
				l[0] = v[j].first;
			else
				l[1] = v[j].first;
			j--;
			int st = i;
			for(; st <= j; st++)
			{
				ll cur = sqr(l[0] - v[st].first) + sqr(l[1] - v[st].first) + sqr(l[0] - l[1]);
				minans = min(minans, cur);
			}
			l[2] = v[j].first;
			i = j;
			lst = 2;
			continue;
		}
	}
	cout << minans << '\n';
}

void multisolve()
{
	int t;
	cin >> t;
	while(t--)
		solve();
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	multisolve();
}


#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <sstream>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <cstdlib>
#include <cstdio>
#include <iterator>
#include <functional>
#include <bitset>
#include <iomanip>
#include <float.h>

#define ll long long

#define FOR(i,a,b)        for(ll i=(a);i<(b);i++)
#define REP(i,n)        FOR(i,0,n)
#define SORT(v)            sort((v).begin(),(v).end())
#define UN(v)            SORT(v),(v).erase(unique((v).begin(),(v).end()),(v).end())
#define CL(a,b)            memset(a,b,sizeof a)
#define pb                push_back

using namespace std;

//#define N 1000009
ll denom = 998244353;//1e9+7;
ll powmod(ll a,ll b) {ll res=1;a%=denom; for(;b;b>>=1){if(b&1)res=res*a%denom;a=a*a%denom;}return res;}

ll val(vector<ll>& r, vector<ll>& g, vector<ll>& b, ll i1, ll i2, ll i3) {
    if (r.size() <= i1 || g.size() <= i2 || b.size() <= i3) return LLONG_MAX;
    return 2*(r[i1]*r[i1] + g[i2]*g[i2] + b[i3]*b[i3] - r[i1]*g[i2] - g[i2]*b[i3] - b[i3]*r[i1]);
}

int main(int argc, const char * argv[])
{
    ios_base::sync_with_stdio(false);
    ll t; cin >> t;
    REP(i, t) {
        ll nr, ng, nb; cin >> nr >> ng >> nb;
        vector<ll> r(nr); REP(j, nr) cin >> r[j];
        vector<ll> g(ng); REP(j, ng) cin >> g[j];
        vector<ll> b(nb); REP(j, nb) cin >> b[j];
        SORT(r); SORT(g); SORT(b);
        ll i1 = 0, i2 = 0, i3 = 0;
        ll result = val(r,g,b,i1,i2,i3);
        while (i1 < nr && i2 < ng && i3 < nb) {
            ll res1 = val(r,g,b,i1+1,i2,i3);
            ll res2 = val(r,g,b,i1,i2+1,i3);
            ll res3 = val(r,g,b,i1,i2,i3+1);
            if (res1 <= res2 && res1 <= res3) {
                result = min(res1, result);
                i1++;
            } else if (res2 <= res1 && res2 <= res3) {
                result = min(res2, result);
                i2++;
            } else {
                result = min(res3, result);
                i3++;
            }
        }
        cout << result << endl;
    }

    return 0;
}


#pragma warning(disable:4996)
#ifdef _DEBUG
#define gets(SS) gets_s(SS, RSIZE_MAX)
#endif
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <stack>
#include <queue>
#include <math.h>
#include <set>
#include <time.h>
#include <deque>
#include <string>
#include <fstream>
#include <assert.h>
#include <bitset>
#include <regex>
#include <iomanip>
#include <unordered_map>

using namespace std;
typedef unsigned int uint;
typedef long long ll;
const long double PI = 3.1415926535897932384626433832795;
const double eps = 1e-10;
const ll mod = 998244353;

ll ans(vector<int> &a, vector<int> &b, vector<int> &c) {
	int x = 0, y = 0;
	ll ans = 4e18;
	for (int i = 0; i < b.size(); i++) {
		while (x < a.size() && a[x] <= b[i]) {
			x++;
		}
		while (y < c.size() && c[y] < b[i]) {
			y++;
		}
		if (x > 0 && a[x - 1] <= b[i] && y < c.size()) {
			ll aa = a[x - 1], bb = b[i], cc = c[y];
			ans = min(ans,
				(aa - bb) * (aa - bb) +
				(aa - cc) * (aa - cc) +
				(cc - bb) * (cc - bb)
			);
		}
	}

	return ans;
}

void sol() {
	int t;
	cin >> t;
	for (int z = 0; z < t; z++) {
		int na, nb, nc;
		cin >> na >> nb >> nc;
		vector<int> a, b, c;
		for (int i = 0; i < na; i++) {
			int x;
			cin >> x;
			a.push_back(x);
		}
		sort(a.begin(), a.end());
		for (int i = 0; i < nb; i++) {
			int x;
			cin >> x;
			b.push_back(x);
		}
		sort(b.begin(), b.end());
		for (int i = 0; i < nc; i++) {
			int x;
			cin >> x;
			c.push_back(x);
		}
		sort(c.begin(), c.end());
		vector<ll> v = { ans(a, b, c), ans(a, c, b), ans(b, a, c), ans(b, c, a), ans(c, a, b), ans(c, b, a) };
		ll res = 4e18;
		for (int i = 0; i < 6; i++) {
			res = min(res, v[i]);
		}
		cout << res << '\n';
	}
}

int main() {
	//#pragma comment(linker, "/STACK:536870912")
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
	//freopen("crossover.in", "r", stdin);
	//freopen("crossover.out", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(12);
	sol();
	return 0;
}


#include <stdio.h>
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <algorithm>

using namespace std;

typedef long long ullong;

void find_closest(vector<ullong>& v, ullong x, int size, ullong &closestLeq, ullong &closestGt) {
	int l = 0;
	int r = size - 1;
	if (v[r] <= x) {
		closestLeq=v[r];
		closestGt = 0ull;
		return;
	}
	if (v[l] > x) {
		closestGt = v[l];
		closestLeq = 0ull;
		return;
	}
	while (l+1 < r) {
		int m = (l + r) >> 1;
		if (v[m] <= x) l = m;
		else r = m;
	}
	closestLeq = v[l];
	closestGt = v[r];
};

ullong ad(ullong x, ullong y) {
	return (x > y) ? (x - y) : (y - x);
};

ullong getBalance(ullong rw, ullong gw, ullong bw) {
	ullong rgw = ad(rw,gw);
	ullong gbw = ad(bw, gw);
	ullong brw = ad(rw, bw);
	return rgw * rgw + gbw * gbw + brw * brw;
};

int main(int argc, char* argv[]) {
	int testsN;
	cin >> testsN;
	vector<vector<ullong>> W(3, vector<ullong>(10000));
	for (size_t test = 0; test < testsN; test++)
	{
		int nr, ng, nb;
		int N[3];
		cin >> N[0] >> N[1] >> N[2];
		for (size_t i = 0; i < N[0]; i++) cin >> W[0][i];
		for (size_t i = 0; i < N[1]; i++) cin >> W[1][i];
		for (size_t i = 0; i < N[2]; i++) cin >> W[2][i];
		for (size_t i = 0; i < 3; i++)
		{
			sort(W[i].begin(), W[i].begin()+N[i]);

		}
		ullong bestBalance = getBalance(W[0][0], W[1][0], W[2][0]);
		for (size_t Wrgbi = 0; Wrgbi < 3; Wrgbi++)
		{
			vector<ullong>& V1 = W[Wrgbi];
			vector<ullong>& V2 = W[(Wrgbi+1)%3];
			vector<ullong>& V3 = W[(Wrgbi + 2) % 3];
			int N1 = N[Wrgbi];
			int N2 = N[(Wrgbi + 1) % 3];
			int N3 = N[(Wrgbi + 2) % 3];
			// nr <= ng <= nb
			for (size_t r = 0; r < N1; r++)
			{
				ullong R = V1[r];
				// find closest G
				ullong gc[2];
				ullong bc[2];
				find_closest(V2, R, N2, gc[0], gc[1]);
				for (size_t gi = 0; gi < 2; gi++)
				{
					ullong G = gc[gi];
					if (G == 0) continue;
					ullong tryG = ad(R, G);
					tryG *= tryG;
					if (tryG + (tryG >> 1) >= bestBalance) continue;
					find_closest(V3, (R + G) >> 1, N3, bc[0], bc[1]);
					for (size_t bi = 0; bi < 2; bi++)
					{
						ullong B = bc[bi];
						if (B == 0) continue;
						bestBalance = min(bestBalance, getBalance(R, G, B));
					}
				}
			}
		}
		cout << bestBalance << '\n';
	}
	return 0;
};


#include <stdio.h>
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <algorithm>

using namespace std;

typedef long long ullong;

void find_closest(vector<ullong>& v, ullong x, int size, ullong &closestLeq, ullong &closestGt) {
	int l = 0;
	int r = size - 1;
	if (v[r] <= x) {
		closestLeq=v[r];
		closestGt = 0ull;
		return;
	}
	if (v[l] > x) {
		closestGt = v[l];
		closestLeq = 0ull;
		return;
	}
	while (l+1 < r) {
		int m = (l + r) >> 1;
		if (v[m] <= x) l = m;
		else r = m;
	}
	closestLeq = v[l];
	closestGt = v[r];
};

ullong ad(ullong x, ullong y) {
	return (x > y) ? (x - y) : (y - x);
};

ullong getBalance(ullong rw, ullong gw, ullong bw) {
	ullong rgw = ad(rw,gw);
	ullong gbw = ad(bw, gw);
	ullong brw = ad(rw, bw);
	return rgw * rgw + gbw * gbw + brw * brw;
};

int main(int argc, char* argv[]) {
	int testsN;
	cin >> testsN;
	vector<vector<ullong>> W(3, vector<ullong>(100000));
	for (size_t test = 0; test < testsN; test++)
	{
		int nr, ng, nb;
		int N[3];
		cin >> N[0] >> N[1] >> N[2];
		for (size_t i = 0; i < N[0]; i++) cin >> W[0][i];
		for (size_t i = 0; i < N[1]; i++) cin >> W[1][i];
		for (size_t i = 0; i < N[2]; i++) cin >> W[2][i];
		for (size_t i = 0; i < 3; i++)
		{
			sort(W[i].begin(), W[i].begin()+N[i]);

		}
		ullong bestBalance = getBalance(W[0][0], W[1][0], W[2][0]);
		for (size_t Wrgbi = 0; Wrgbi < 3; Wrgbi++)
		{
			vector<ullong>& V1 = W[Wrgbi];
			vector<ullong>& V2 = W[(Wrgbi+1)%3];
			vector<ullong>& V3 = W[(Wrgbi + 2) % 3];
			int N1 = N[Wrgbi];
			int N2 = N[(Wrgbi + 1) % 3];
			int N3 = N[(Wrgbi + 2) % 3];
			// nr <= ng <= nb
			for (size_t r = 0; r < N1; r++)
			{
				ullong R = V1[r];
				// find closest G
				ullong gc[2];
				ullong bc[2];
				find_closest(V2, R, N2, gc[0], gc[1]);
				for (size_t gi = 0; gi < 2; gi++)
				{
					ullong G = gc[gi];
					if (G == 0) continue;
					ullong tryG = ad(R, G);
					tryG *= tryG;
					if (tryG + (tryG >> 1) >= bestBalance) continue;
					find_closest(V3, (R + G) >> 1, N3, bc[0], bc[1]);
					for (size_t bi = 0; bi < 2; bi++)
					{
						ullong B = bc[bi];
						if (B == 0) continue;
						bestBalance = min(bestBalance, getBalance(R, G, B));
					}
				}
			}
		}
		cout << bestBalance << '\n';
	}
	return 0;
};


#include <deque>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <iostream>
#include <tuple>
#include <queue>
using namespace std;

set<int64_t> rs, gs, bs;
int64_t r = -1, g = -1, b = -1;

bool grb(int r_)
{
    r = r_;
    auto b_ = bs.lower_bound(r);
    if (b_ == bs.end())
        return 0;
    b = *b_;

    auto g_ = gs.lower_bound(r);
    if (g_ != gs.end() && r == *g_)
    {
        g = r;
        return 1;
    }
    if (g_ == gs.begin())
        return 0;
    g = *(--g_);
    return 1;
}
bool brg(int r_)
{
    r = r_;
    auto g_ = gs.lower_bound(r);
    if (g_ == gs.end())
        return 0;
    g = *g_;

    auto b_ = bs.lower_bound(r);
    if (b_ != bs.end() && r == *b_)
    {
        b = r;
        return 1;
    }
    if (b_ == bs.begin())
        return 0;
    b = *(--b_);
    return 1;
}
bool rgb(int g_)
{
    g = g_;
    auto b_ = bs.lower_bound(g);
    if (b_ == bs.end())
        return 0;
    b = *b_;

    auto r_ = rs.lower_bound(g);
    if (r_ != rs.end() && g == *r_)
    {
        r = g;
        return 1;
    }
    if (r_ == rs.begin())
        return 0;
    r = *(--r_);
    return 1;
}
bool bgr(int g_)
{
    g = g_;
    auto r_ = rs.lower_bound(g);
    if (r_ == rs.end())
        return 0;
    r = *r_;

    auto b_ = bs.lower_bound(g);
    if (b_ != bs.end() && g == *b_)
    {
        b = g;
        return 1;
    }
    if (b_ == bs.begin())
        return 0;
    b = *(--b_);
    return 1;
}
bool rbg(int b_)
{
    b = b_;
    auto g_ = gs.lower_bound(b);
    if (g_ == gs.end())
        return 0;
    g = *g_;

    auto r_ = rs.lower_bound(b);
    if (r_ != rs.end() && b == *r_)
    {
        r = b;
        return 1;
    }
    if (r_ == rs.begin())
        return 0;
    r = *(--r_);
    return 1;
}
bool gbr(int b_)
{
    b = b_;
    auto r_ = rs.lower_bound(b);
    if (r_ == rs.end())
        return 0;
    r = *r_;

    auto g_ = gs.lower_bound(b);
    if (g_ != gs.end() && b == *g_)
    {
        g = b;
        return 1;
    }
    if (g_ == gs.begin())
        return 0;
    g = *(--g_);
    return 1;
}

int64_t checkMinVal(int64_t minVal)
{
    int64_t minVal_ = (r - g) * (r - g) + (g - b) * (g - b) + (b - r) * (b - r);
    return min(minVal, minVal_);
}

int main()
{
    int t;
    cin >> t;
    for (int k = 0; k < t; k++)
    {
        int nr, ng, nb;
        cin >> nr >> ng >> nb;
        rs.clear();
        for (int i = 0; i < nr; i++)
        {
            int x;
            cin >> x;
            rs.insert(x);
        }
        gs.clear();
        for (int i = 0; i < ng; i++)
        {
            int x;
            cin >> x;
            gs.insert(x);
        }
        bs.clear();
        for (int i = 0; i < nb; i++)
        {
            int x;
            cin >> x;
            bs.insert(x);
        }

        int64_t minVal = INT64_MAX;

        for (auto r_ : rs)
        {
            if (grb(r_))
                minVal = checkMinVal(minVal);
            if (brg(r_))
                minVal = checkMinVal(minVal);
        }
        for (auto g_ : gs)
        {
            if (rgb(g_))
                minVal = checkMinVal(minVal);
            if (bgr(g_))
                minVal = checkMinVal(minVal);
        }
        for (auto b_ : bs)
        {
            if (rbg(b_))
                minVal = checkMinVal(minVal);
            if (gbr(b_))
                minVal = checkMinVal(minVal);
        }

        cout << minVal << '\n';
    }

    return 0;
}


#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#define speed ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define eps 1e-8
#define inf INT_MAX
#define mod 1000000009
using namespace std;

ll calc(ll a, ll b, ll c) {
	return (a - b) * (a - b) + (a - c) * (a - c) + (c - b) * (c - b);
}

int main() {
	speed;
	int t;
	cin >> t;
	while (t--) {
		int n[3], v;
		set<int>ar[3];
		cin >> n[0] >> n[1] >> n[2];
		for (int i = 0; i < 3; ++i) {
			for (int j = 0; j < n[i]; ++j) {
				cin >> v;
				ar[i].insert(v);
			}
		}
		ll ans = LLONG_MAX;
		for (auto i : ar[0]) {
			auto itr = ar[1].lower_bound(i);
			if (itr != ar[1].end()) {
				auto jtr = ar[2].lower_bound((*itr + i) / 2);
				if (jtr != ar[2].end())
					ans = min(ans, calc(i, *itr, *jtr));
				if (jtr != ar[2].begin()) {
					jtr--;
					ans = min(ans, calc(i, *itr, *jtr));
				}
			}
			if (itr != ar[1].begin()) {
				itr--;
				auto jtr = ar[2].lower_bound((*itr + i) / 2);
				if (jtr != ar[2].end())
					ans = min(ans, calc(i, *itr, *jtr));
				if (jtr != ar[2].begin()) {
					jtr--;
					ans = min(ans, calc(i, *itr, *jtr));
				}
			}

			itr = ar[2].lower_bound(i);
			if (itr != ar[2].end()) {
				auto jtr = ar[1].lower_bound((*itr + i) / 2);
				if (jtr != ar[1].end())
					ans = min(ans, calc(i, *itr, *jtr));
				if (jtr != ar[1].begin()) {
					jtr--;
					ans = min(ans, calc(i, *itr, *jtr));
				}
			}
			if (itr != ar[2].begin()) {
				itr--;
				auto jtr = ar[1].lower_bound((*itr + i) / 2);
				if (jtr != ar[1].end())
					ans = min(ans, calc(i, *itr, *jtr));
				if (jtr != ar[1].begin()) {
					jtr--;
					ans = min(ans, calc(i, *itr, *jtr));
				}
			}
		}
		cout << ans << '\n';
	}
}


#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ff first
#define ss second
#define input(a) scanf("%lld",&a)
#define M 1000000007
#define inf 1<<30

using namespace std;

typedef long long int ll;
typedef pair<ll,ll> ii;
typedef pair<ll,ii> iii;

ll gcd(ll a,ll b)
{
    if(a==0)
        return b;
    return gcd(b%a,a);
}

ll bigMod(ll base,ll power)
{
    if(power==0)
        return 1;
    ll x=bigMod(base,power/2);
    x=(x*x)%M;
    if(power&1)
        x=(x*base)%M;
    return x;
}

ll nr,ng,nb,r[100100],g[100100],b[100100],msk,res;
ll *p;
vector<ll>gn,bn;

ll cal(ll x,ll y,ll z)
{
    return (x-y)*(x-y)+(y-z)*(y-z)+(z-x)*(z-x);
}

int main()
{
    int t;
    cin>>t;
    while(t--){
        cin>>nr>>ng>>nb;
        for(int i=0;i<nr;i++)
            cin>>r[i];
        for(int i=0;i<ng;i++)
            cin>>g[i];
        for(int i=0;i<nb;i++)
            cin>>b[i];
        sort(r,r+nr);
        sort(g,g+ng);
        sort(b,b+nb);
        res=-1;
        for(int i=0;i<nr;i++){
            gn.clear();
            bn.clear();
            p=lower_bound(g,g+ng,r[i]);
            if(p==g+ng)
                gn.push_back(*(p-1));
            else if(*p==r[i]||p==g)
                gn.push_back(*p);
            else{
                gn.push_back(*p);
                gn.push_back(*(p-1));
            }
            p=lower_bound(b,b+nb,r[i]);
            if(p==b+nb)
                bn.push_back(*(p-1));
            else if(*p==r[i]||p==b)
                bn.push_back(*p);
            else{
                bn.push_back(*p);
                bn.push_back(*(p-1));
            }
            msk=bn.size();
            for(int i=0;i<gn.size();i++){
                p=lower_bound(b,b+nb,gn[i]);
                if(p==b+nb)
                    bn.push_back(*(p-1));
                else if(*p==gn[i]||p==b)
                    bn.push_back(*p);
                else{
                    bn.push_back(*p);
                    bn.push_back(*(p-1));
                }
            }
            for(int i=0;i<msk;i++){
                p=lower_bound(g,g+ng,bn[i]);
                if(p==g+ng)
                    gn.push_back(*(p-1));
                else if(*p==bn[i]||p==g)
                    gn.push_back(*p);
                else
                    gn.push_back(*(p-1));
            }
            for(int j=0;j<gn.size();j++){
                for(int k=0;k<bn.size();k++){
                    if(res==-1)
                        res=cal(r[i],gn[j],bn[k]);
                    else
                        res=min(res,cal(r[i],gn[j],bn[k]));
                }
            }
        }
        cout<<res<<endl;
    }
    return 0;
}


#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ff first
#define ss second
#define input(a) scanf("%lld",&a)
#define M 1000000007
#define inf 1<<30

using namespace std;

typedef long long int ll;
typedef pair<ll,ll> ii;
typedef pair<ll,ii> iii;

ll gcd(ll a,ll b)
{
    if(a==0)
        return b;
    return gcd(b%a,a);
}

ll bigMod(ll base,ll power)
{
    if(power==0)
        return 1;
    ll x=bigMod(base,power/2);
    x=(x*x)%M;
    if(power&1)
        x=(x*base)%M;
    return x;
}

ll n[3],gem[3][100100],msk,res;
ll *p;
vector<ll>lst[3][3][100100];

ll cal(ll x,ll y,ll z)
{
    return (x-y)*(x-y)+(y-z)*(y-z)+(z-x)*(z-x);
}

ll ara[10];

ll dfs(ll clr,ll ind,ll msk,ll nw)
{
    ara[nw]=gem[clr][ind];
    if(nw==2){
        return cal(ara[0],ara[1],ara[2]);
    }
    ll ret=-1,v;
    for(int i=0;i<3;i++){
        if(msk&(1<<i))
            continue;
        for(int j=0;j<lst[clr][i][ind].size();j++){
            v=lst[clr][i][ind][j];
            if(ret==-1)
                ret=dfs(i,v,msk|(1<<i),nw+1);
            else
                ret=min(ret,dfs(i,v,msk|(1<<i),nw+1));
        }
    }
    return ret;
}

int main()
{
    int t;
    cin>>t;
    while(t--){
        for(int i=0;i<3;i++)
            cin>>n[i];
        for(int i=0;i<3;i++){
            for(int j=0;j<n[i];j++){
                cin>>gem[i][j];
                for(int k=0;k<3;k++)
                    lst[i][k][j].clear();
            }
        }
        for(int i=0;i<3;i++)
            sort(gem[i],gem[i]+n[i]);
        for(int i=0;i<3;i++){
            for(int j=0;j<n[i];j++){
                for(int k=0;k<3;k++){
                    if(k==i)
                        continue;
                    p=lower_bound(gem[k],gem[k]+n[k],gem[i][j]);
                    if(p==gem[k]+n[k])
                        lst[i][k][j].push_back(n[k]-1);
                    else if(*p==gem[i][j]||p==gem[k])
                        lst[i][k][j].push_back(p-gem[k]);
                    else {
                        lst[i][k][j].push_back(p-gem[k]);
                        lst[i][k][j].push_back(p-gem[k]-1);
                    }
                }
            }
        }
        ll ret=cal(gem[0][0],gem[1][0],gem[2][0]);
        for(int i=0;i<3;i++){
            for(int j=0;j<n[i];j++){
                ret=min(ret,dfs(i,j,1<<i,0));
            }
        }
        cout<<ret<<endl;
    }
    return 0;
}


#include <cstdio>
#include <algorithm>
#include <iostream>
#include <functional>
#define ll long long
int const N = 1e5 + 10;
using namespace std;
ll a[N], c[N], b[N];

ll ans(ll x, ll y, ll z) {
	return (ll)(x - y) * (x - y) + (ll)(y - z) * (y - z) + (ll)(x - z) * (x - z);
}
ll res;
int na, nb, nc;
void findt(ll at, ll* bt, ll* ct, int nb, int nc) {
	if (bt[0] > at || ct[nc - 1] < at) return;
	int nnb = upper_bound(bt, bt + nb, at) - bt-1;
	int nnc = lower_bound(ct, ct + nc, at) - ct;
	ll bnum = bt[nnb];
	ll cnum = ct[nnc];
	res = min(res, ans( bnum,at, cnum));
}
int main() {
	int t;

	cin >> t;
	while (t--) {

		cin >> na >> nb >> nc;
		for (int i = 0; i < na; i++)
			scanf("%lld", &a[i]);
		for (int i = 0; i < nb; i++)
			scanf("%lld", &b[i]);
		for (int i = 0; i < nc; i++)
			scanf("%lld", &c[i]);
		sort(a, a + na);
		sort(b, b + nb);
		sort(c, c + nc);
		 res = 2 * 1e18;
		 //cout << lower_bound(a, a + na, (ll)4) - a;
		for (int i = 0; i < na; i++) {
			findt(a[i], b, c,nb, nc);
			findt(a[i], c, b, nc,nb);
		}
		for (int i = 0; i < nb; i++) {
			findt(b[i], a, c,na, nc);
			findt(b[i], c, a,nc, na);
		}
		for (int i = 0; i < nc; i++) {
			findt(c[i], b, a, nb,na);
			findt(c[i], a, b,na, nb);
		}
		cout << res << endl;
	}

	return 0;
}


#include <cstdio>
#include <algorithm>
#include <iostream>
#define ll long long
int const N = 1e5 + 10;
using namespace std;
ll a[N], c[N], b[N];
int cmp(ll a, ll b) {
	return a < b;
}
ll ans(ll x, ll y, ll z) {
	return (ll)(x - y) * (x - y) + (ll)(y - z) * (y - z) + (ll)(x - z) * (x - z);
}
ll res;
int na, nb, nc;
void findt(ll at, ll *bt, ll *ct, int nc) {
	int nnb = lower_bound(bt, bt + nb, at) - bt;
	int nnc = upper_bound(ct, ct + nc, at) - ct;
	if (nnc == nc) return;
	ll bnum = bt[nnb];
	ll cnum = ct[nnc];
	res = min(res, ans(at, bnum, cnum));
}
int main() {
	int t;

	cin >> t;
	while (t--) {

		cin >> na >> nb >> nc;
		for (int i = 0; i < na; i++)
			scanf("%lld", &a[i]);
		for (int i = 0; i < nb; i++)
			scanf("%lld", &b[i]);
		for (int i = 0; i < nc; i++)
			scanf("%lld", &c[i]);
		sort(a, a + na, cmp);
		sort(b, b + nb, cmp);
		sort(c, c + nc, cmp);
		 res = 2 * 1e18;
		for (int i = 0; i < na; i++) {
			findt(a[i], b, c, nc);
			findt(a[i], c, b, nb);
		}
		for (int i = 0; i < nb; i++) {
			findt(b[i], a, c, nc);
			findt(b[i], c, a, na);
		}
		for (int i = 0; i < nc; i++) {
			findt(c[i], b, a, na);
			findt(c[i], a, b, nb);
		}
		cout << res << endl;
	}

	return 0;
}


#include <cstdio>
#include <algorithm>
#include <iostream>
#define ll long long
int const N = 1e5 + 10;
using namespace std;
ll a[N], c[N], b[N];
ll ans(ll x, ll y, ll z) {
	return (ll)(x - y) * (x - y) + (ll)(y - z) * (y - z) + (ll)(x - z) * (x - z);
}
int main() {
	int t;
	int na, nb, nc;
	cin >> t;
	while (t--) {

		cin >> na >> nb >> nc;
		for (int i = 0; i < na; i++)
			scanf("%lld", &a[i]);
		for (int i = 0; i < nb; i++)
			scanf("%lld", &b[i]);
		for (int i = 0; i < nc; i++)
			scanf("%lld", &c[i]);
		sort(a, a + na);
		sort(b, b + nb);
		sort(c, c + nc);
		ll res = 2 * 1e18;
		for (int i = 0; i < na; i++) {
			int nnb = lower_bound(b, b + nb, a[i]) - b;
			ll bnum;
			if (nnb >= nb)
				bnum = b[nb - 1];
			else bnum = b[lower_bound(b, b + nb, a[i]) - b];

			int nnc = upper_bound(c, c + nc, a[i]) - c;
			ll cnum = c[nnc >= nc ? nc-1: nnc];
			res = min(res, ans(a[i], bnum, cnum));
		}
		for (int i = 0; i < nb; i++) {
			int nna = lower_bound(a, a + na, b[i]) - a;
			ll anum;
			if (nna >= na) anum = a[na - 1];
			else anum = a[lower_bound(a, a + na, b[i]) - a];
			int nnc = upper_bound(c, c + nc, b[i]) - c;
			ll cnum;
			if (nnc >= nc)
				cnum = c[nc - 1];
			else
				cnum = c[upper_bound(c, c + nc, b[i]) - c];
			res = min(res, ans(b[i], anum, cnum));
		}
		for (int i = 0; i < nc; i++) {
			int nnb = lower_bound(b, b + nb, a[i]) - b;
			ll bnum;
			if (nnb >= nb) bnum = b[nb - 1];
			else
				 bnum = b[nnb];
			int nna = upper_bound(a, a + na, c[i]) - a;
			ll anum;
			if(nna >= na)
				anum = a[na-1];
			else
				anum = a[nna];
			res = min(res, ans(c[i], bnum, anum));
		}
		cout << res << endl;
	}

	return 0;
}


#include <cstdio>
#include <algorithm>
#include <iostream>
#define ll long long
int const N = 1e5 + 10;
using namespace std;
ll a[N], c[N], b[N];
int cmp(ll a, ll b) {
	return a < b;
}
ll ans(ll x, ll y, ll z) {
	return (ll)(x - y) * (x - y) + (ll)(y - z) * (y - z) + (ll)(x - z) * (x - z);
}
ll res;
int na, nb, nc;
void findt(ll at, ll *bt, ll *ct) {
	int nnb = lower_bound(bt, bt + nb, at) - bt;
	int nnc = upper_bound(ct, ct + nc, at) - ct;
	if (nnc == nc) return;
	ll bnum = bt[nnb];
	ll cnum = ct[nnc];
	res = min(res, ans(at, bnum, cnum));
}
int main() {
	int t;

	cin >> t;
	while (t--) {

		cin >> na >> nb >> nc;
		for (int i = 0; i < na; i++)
			scanf("%lld", &a[i]);
		for (int i = 0; i < nb; i++)
			scanf("%lld", &b[i]);
		for (int i = 0; i < nc; i++)
			scanf("%lld", &c[i]);
		sort(a, a + na, cmp);
		sort(b, b + nb, cmp);
		sort(c, c + nc, cmp);
		 res = 2 * 1e18;
		for (int i = 0; i < na; i++) {
			findt(a[i], b, c);
			findt(a[i], c, b);
		}
		for (int i = 0; i < nb; i++) {
			findt(b[i], a, c);
			findt(b[i], c, a);
		}
		for (int i = 0; i < nc; i++) {
			findt(c[i], b, a);
			findt(c[i], a, b);
		}
		cout << res << endl;
	}

	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_set>
#include <math.h>
#include <unordered_map>
#include <string>
#include <bitset>
#include <sstream>
#include <locale>
#include <queue>
#include <functional>
#include <regex>
#include <memory>
#include <utility>
#include <type_traits>
#include <cctype>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cassert>
#include <array>
#include <random>
#include <numeric>
#include <optional>
#include <tuple>

using namespace std;

typedef long long ll;

template <typename T>
vector<T> nextv(int n = -1)
{
	if (n == -1) cin >> n;

	vector<T> result(n);
	for (int i = 0; i < n; ++i)
	{
		T temp;
		cin >> temp;
		result[i] = temp;
	}

	return result;
}

template <typename T>
T next()
{
	T result;
	cin >> result;
	return result;
}

int nexti()
{
	return next<int>();
}

ll nll() {
	return next<ll>();
}

template <typename T>
vector<vector<T>> vv(int n, int m, T init)
{
	return vector<vector<T>>(n, vector<T>(m, init));
}

template<typename T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vector) {
	os << "[";
	for (size_t i = 0; i < vector.size(); ++i) {
		os << vector[i];
		if (i != vector.size() - 1) {
			os << ", ";
		}
	}
	os << "]";
	return os;
}

struct ListNode {
	int val;
	ListNode* next;
	ListNode(int x) : val(x), next(NULL) {}
};

struct TreeNode {
	int val;
	TreeNode* left = nullptr;
	TreeNode* right = nullptr;
	TreeNode(int val) : val(val) {}
};

std::ostream& operator<<(std::ostream& os, ListNode* head) {
	os << "[";
	while (head) {
		os << head->val;
		if (head->next != nullptr) {
			os << ", ";
		}

		head = head->next;
	}
	os << "]";
	return os;
}

//--------------------------------------------------

ll solve(const vector<ll>& xs, const vector<ll>& ys, const vector<ll>& zs) {
	ll result = LLONG_MAX;
	for (const ll x : xs) {
		auto itY = upper_bound(ys.begin(), ys.end(), x);
		if (itY != ys.begin()) --itY;

		auto itZ = upper_bound(zs.begin(), zs.end(), x);
		if (itZ != zs.begin()) --itZ;

		ll y = *itY;
		ll z = *itZ;

		ll localResult = (x - y) * (x - y) + (y - z) * (y - z) + (z - x) * (z - x);

		result = min(result, localResult);
	}

	return result;
}

void solve() {
	ll xn = nll();
	ll yn = nll();
	ll zn = nll();

	auto xs = nextv<ll>(xn);
	auto ys = nextv<ll>(yn);
	auto zs = nextv<ll>(zn);

	sort(xs.begin(), xs.end());
	sort(ys.begin(), ys.end());
	sort(zs.begin(), zs.end());

	ll result = LLONG_MAX;
	result = min(result, solve(xs, ys, zs));
	result = min(result, solve(ys, zs, xs));
	result = min(result, solve(zs, xs, ys));

	cout << result << endl;
}

int main()
{
	std::ios::sync_with_stdio(false);
	cin.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
#endif

	ll t = nll();
	while (t-- > 0) {
		solve();
	}

	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_set>
#include <math.h>
#include <unordered_map>
#include <string>
#include <bitset>
#include <sstream>
#include <locale>
#include <queue>
#include <functional>
#include <regex>
#include <memory>
#include <utility>
#include <type_traits>
#include <cctype>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cassert>
#include <array>
#include <random>
#include <numeric>
#include <optional>
#include <tuple>

using namespace std;

typedef long long ll;

template <typename T>
vector<T> nextv(int n = -1)
{
	if (n == -1) cin >> n;

	vector<T> result(n);
	for (int i = 0; i < n; ++i)
	{
		T temp;
		cin >> temp;
		result[i] = temp;
	}

	return result;
}

template <typename T>
T next()
{
	T result;
	cin >> result;
	return result;
}

int nexti()
{
	return next<int>();
}

ll nll() {
	return next<ll>();
}

template <typename T>
vector<vector<T>> vv(int n, int m, T init)
{
	return vector<vector<T>>(n, vector<T>(m, init));
}

template<typename T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vector) {
	os << "[";
	for (size_t i = 0; i < vector.size(); ++i) {
		os << vector[i];
		if (i != vector.size() - 1) {
			os << ", ";
		}
	}
	os << "]";
	return os;
}

struct ListNode {
	int val;
	ListNode* next;
	ListNode(int x) : val(x), next(NULL) {}
};

struct TreeNode {
	int val;
	TreeNode* left = nullptr;
	TreeNode* right = nullptr;
	TreeNode(int val) : val(val) {}
};

std::ostream& operator<<(std::ostream& os, ListNode* head) {
	os << "[";
	while (head) {
		os << head->val;
		if (head->next != nullptr) {
			os << ", ";
		}

		head = head->next;
	}
	os << "]";
	return os;
}

//--------------------------------------------------

ll solve(const vector<ll>& xs, const vector<ll>& ys, const vector<ll>& zs) {
	ll result = LLONG_MAX;
	for (const ll x : xs) {
		auto itY = lower_bound(ys.begin(), ys.end(), x);
		if (itY == ys.end()) continue;

		auto itZ = upper_bound(zs.begin(), zs.end(), x);
		if (itZ != zs.begin()) --itZ;

		ll y = *itY;
		ll z = *itZ;

		ll localResult = (x - y) * (x - y) + (y - z) * (y - z) + (z - x) * (z - x);

		result = min(result, localResult);
	}

	return result;
}

void solve() {
	ll xn = nll();
	ll yn = nll();
	ll zn = nll();

	auto xs = nextv<ll>(xn);
	auto ys = nextv<ll>(yn);
	auto zs = nextv<ll>(zn);

	sort(xs.begin(), xs.end());
	sort(ys.begin(), ys.end());
	sort(zs.begin(), zs.end());

	ll result = LLONG_MAX;
	result = min(result, solve(xs, ys, zs));
	result = min(result, solve(xs, zs, ys));
	result = min(result, solve(ys, zs, xs));
	result = min(result, solve(ys, xs, zs));
	result = min(result, solve(zs, xs, ys));
	result = min(result, solve(zs, ys, xs));

	cout << result << endl;
}

int main()
{
	std::ios::sync_with_stdio(false);
	cin.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
#endif

	ll t = nll();
	while (t-- > 0) {
		solve();
	}

	return 0;
}


#include <algorithm>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cmath>
#include <string>
#include <vector>
#include <bitset>

#define sp << " "
#define sps << " " <<
#define ln << "\n"
#define vi vector<int>
#define pii pair<int, int>
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define optimise cin.sync_with_stdio(false); cout.sync_with_stdio(false); cin.tie(NULL);

typedef long long ll;
typedef unsigned long long ull;
using namespace std;

template<class T>
istream& operator>> (istream& is, vector<T>& vec) { for (int i = 0; i < (int)vec.size(); ++i)is >> vec[i]; return is; }
template<class T>
ostream& operator<< (ostream& os, vector<T>& vec) { for (int i = 0; i < (int)vec.size(); ++i)os << vec[i] sp; return os; }
template<class T>
istream& operator>> (istream& is, pair<T, T>& a) { is >> a.first >> a.second; return is; }

const double pi = acos(-1.0);
const ll mod = (int)1e9 + 7;
const ll INF = 2e18;
const int inf = 2e9;
const int maxlen = (int)2e5 + 10;
const double eps = 1e-4;
//----------------------------
ll dist(int a, int b, int c){
    return 1ll * (a - b) * (a - b) + 1ll * (a - c) * (a - c) + 1ll * (b - c) * ( b - c);
}
void solve() {
    int nr, ng, nb;
    cin >> nr >> ng >> nb;
    vi r(nr), g(ng), b(nb);
    cin >> r >> g >> b;
    sort(all(r));
    sort(all(g));
    sort(all(b));
    map<int, bool> mr, mb, mg;
    vector<int> x;

    for (auto p : r) {
        x.push_back(p);
        mr[p] = 1;
    }
    for (auto p : g) {
        x.push_back(p);
        mg[p] = 1;
    }
    for (auto p : b) {
        x.push_back(p);
        mb[p] = 1;
    }

    sort(all(x));
    x.resize(unique(all(x)) - x.begin());
    ll ans = INF;
    ll lastr = -1, lastg = -1, lastb = -1;

    for (int i = 0; i < x.size(); ++i) {
        if (mr[x[i]])lastr = x[i];
        if (mg[x[i]])lastg = x[i];
        if (mb[x[i]])lastb = x[i];
        if (lastr != -1 && lastb != -1 && lastg != -1) {
            ans = min(ans, dist(lastr, lastb, lastg));

            if (lastr <= lastg && lastg <= lastb) {//g
                for (auto it = upper_bound(all(g), lastr) - g.begin(); it < g.size() && g[it] <= lastb; ++it)
                    ans = min(ans, dist(lastr, g[it], lastb));
            }
            if (lastb <= lastg && lastg <= lastr) {//g
                for (auto it = upper_bound(all(g), lastb) - g.begin(); it < g.size() && g[it] <= lastr; ++it)
                    ans = min(ans, dist(lastr, g[it], lastb));
            }

            if (lastg <= lastr && lastr <= lastb) {//r
                for (auto it = upper_bound(all(r), lastg) - r.begin(); it < r.size() && r[it] <= lastb; ++it)
                    ans = min(ans, dist(lastg, r[it], lastb));
            }

            if (lastb <= lastr && lastr <= lastg) {//r
                for (auto it = upper_bound(all(r), lastb) - r.begin(); it < r.size() && r[it] <= lastb; ++it)
                    ans = min(ans, dist(lastg, r[it], lastg));
            }

            if (lastg <= lastb && lastb <= lastr) {//b
                for (auto it = upper_bound(all(b), lastg) - b.begin(); it < b.size() && b[it] <= lastr; ++it)
                    ans = min(ans, dist(lastg, b[it], lastr));
            }
            if (lastr <= lastb && lastb <= lastg) {//b
                for (auto it = upper_bound(all(b), lastr) - b.begin(); it < b.size() && b[it] <= lastg; ++it)
                    ans = min(ans, dist(lastr, b[it], lastg));
            }
        }
    }

    cout << ans ln;
}

int main() {
    optimise
#ifdef _DEBUG
    freopen("IN.TXT", "r", stdin);
#else
    //freopen("unequal.in", "r", stdin);
    //freopen("unequal.out", "w", stdout);
#endif

    int t = 1;
    cin >> t;
    while(t--){
        solve();
    }
    return 0;
}


#include <algorithm>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cmath>
#include <string>
#include <vector>
#include <bitset>

#define sp << " "
#define sps << " " <<
#define ln << "\n"
#define vi vector<int>
#define pii pair<int, int>
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define optimise cin.sync_with_stdio(false); cout.sync_with_stdio(false); cin.tie(NULL);

typedef long long ll;
typedef unsigned long long ull;
using namespace std;

template<class T>
istream& operator>> (istream& is, vector<T>& vec) { for (int i = 0; i < (int)vec.size(); ++i)is >> vec[i]; return is; }
template<class T>
ostream& operator<< (ostream& os, vector<T>& vec) { for (int i = 0; i < (int)vec.size(); ++i)os << vec[i] sp; return os; }
template<class T>
istream& operator>> (istream& is, pair<T, T>& a) { is >> a.first >> a.second; return is; }

const double pi = acos(-1.0);
const ll mod = (int)1e9 + 7;
const ll INF = 2e18;
const int inf = 2e9;
const int maxlen = (int)2e5 + 10;
const double eps = 1e-4;
//----------------------------
ll dist(int a, int b, int c){
    return 1ll * (a - b) * (a - b) + 1ll * (a - c) * (a - c) + 1ll * (b - c) * ( b - c);
}
void solve() {
    int nr, ng, nb;
    cin >> nr >> ng >> nb;
    vi r(nr), g(ng), b(nb);
    cin >> r >> g >> b;
    map<int, bool> mr, mb, mg;
    vector<int> x;
    for (auto p : r) {
        x.push_back(p);
        mr[p] = 1;
    }
    for (auto p : g) {
        x.push_back(p);
        mg[p] = 1;
    }
    for (auto p : b) {
        x.push_back(p);
        mb[p] = 1;
    }

    sort(all(x));
    x.resize(unique(all(x)) - x.begin());
    ll ans = INF;
    ll lastr = -1, lastg = -1, lastb = -1;

    for (int i = 0; i < x.size(); ++i) {
        if (mr[x[i]])lastr = x[i];
        if (mg[x[i]])lastg = x[i];
        if (mb[x[i]])lastb = x[i];
        if (lastr != -1 && lastb != -1 && lastg != -1) {
            ans = min(ans, dist(lastb, lastg, lastr));
        }
    }
    reverse(all(x));

    lastr = -1, lastg = -1, lastb = -1;
    for (int i = 0; i < x.size(); ++i) {
        if (mr[x[i]])lastr = x[i];
        if (mg[x[i]])lastg = x[i];
        if (mb[x[i]])lastb = x[i];
        if (lastr != -1 && lastb != -1 && lastg != -1) {
            ans = min(ans, dist(lastb, lastg, lastr));
        }
    }

    cout << ans ln;
}

int main() {
    optimise
#ifdef _DEBUG
    freopen("IN.TXT", "r", stdin);
#else
    //freopen("unequal.in", "r", stdin);
    //freopen("unequal.out", "w", stdout);
#endif

    int t = 1;
    cin >> t;
    while(t--){
        solve();
    }
    return 0;
}


#include <algorithm>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cmath>
#include <string>
#include <vector>
#include <bitset>

#define sp << " "
#define sps << " " <<
#define ln << "\n"
#define vi vector<int>
#define pii pair<int, int>
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define optimise cin.sync_with_stdio(false); cout.sync_with_stdio(false); cin.tie(NULL);

typedef long long ll;
typedef unsigned long long ull;
using namespace std;

template<class T>
istream& operator>> (istream& is, vector<T>& vec) { for (int i = 0; i < (int)vec.size(); ++i)is >> vec[i]; return is; }
template<class T>
ostream& operator<< (ostream& os, vector<T>& vec) { for (int i = 0; i < (int)vec.size(); ++i)os << vec[i] sp; return os; }
template<class T>
istream& operator>> (istream& is, pair<T, T>& a) { is >> a.first >> a.second; return is; }

const double pi = acos(-1.0);
const ll mod = (int)1e9 + 7;
const ll INF = 2e18;
const int inf = 2e9;
const int maxlen = (int)2e5 + 10;
const double eps = 1e-4;
//----------------------------
ll dist(int a, int b, int c){
    return 1ll * (a - b) * (a - b) + 1ll * (a - c) * (a - c) + 1ll * (b - c) * ( b - c);
}
void solve() {
    int nr, ng, nb;
    cin >> nr >> ng >> nb;
    vi r(nr), g(ng), b(nb);
    cin >> r >> g >> b;
    sort(all(r));
    sort(all(g));
    sort(all(b));
    ll ans = INF;
    int mrr = 0, mgg = 0, mbb = 0;
    int mnrr = 0, mngg = 0, mnbb = 0;

    for(int i = 0; i < r.size(); ++i){
        while(mngg + 1 < g.size() &&  g[mngg + 1] <= r[i])mngg++;
        while(mnbb + 1 < b.size() &&  b[mnbb + 1] <= r[i])mnbb++;

        while(mgg < g.size() && g[mgg] < r[i])mgg++;
        while(mbb < b.size() && b[mbb] < r[i])mbb++;

        if(mgg < g.size() && mnbb < b.size()){
            if(g[mgg] >= r[i] && b[mnbb] <= r[i])
            ans = min(ans, dist(r[i], b[mnbb], g[mgg]));
        }

        if(mngg < g.size() && mbb < b.size()){
            if(g[mngg] <= r[i] && b[mbb] >= r[i])
                ans = min(ans, dist(r[i], b[mbb], g[mngg]));
        }
    }
    mrr = 0, mgg = 0, mbb = 0;
    mnrr = 0, mngg = 0, mnbb = 0;
    for(int i = 0; i < g.size(); ++i){
        while(mnrr + 1 < r.size() &&  r[mnrr + 1] <= g[i])mnrr++;
        while(mnbb + 1 < b.size() &&  b[mnbb + 1] <= g[i])mnbb++;

        while(mrr < r.size() && r[mrr] < g[i])mrr++;
        while(mbb < b.size() && b[mbb] < g[i])mbb++;

        if(mrr < r.size() && mnbb < b.size()){
            if(r[mrr] >= g[i] && b[mnbb] <= g[i])
                ans = min(ans, dist(g[i], b[mnbb], r[mrr]));
        }

        if(mnrr < r.size() && mbb < b.size()){
            if(r[mnrr] <= g[i] && b[mbb] >= g[i])
                ans = min(ans, dist(g[i], b[mbb], r[mnrr]));
        }
    }

    mrr = 0, mgg = 0, mbb = 0;
    mnrr = 0, mngg = 0, mnbb = 0;
    for(int i = 0; i < b.size(); ++i){
        while(mnrr + 1 < r.size() &&  r[mnrr + 1] <= b[i])mnrr++;
        while(mngg + 1 < g.size() &&  g[mngg + 1] <= b[i])mngg++;

        while(mrr < r.size() && r[mrr] < b[i])mrr++;
        while(mgg < g.size() && g[mgg] < b[i])mgg++;

        if(mrr < r.size() && mngg < g.size()){
            if(r[mrr] >= b[i] && g[mngg] <= b[i])
                ans = min(ans, dist(b[i], g[mngg], r[mrr]));
        }

        if(mnrr < r.size() && mgg < g.size()){
            if(r[mnrr] <= b[i] && g[mgg] >= b[i])
                ans = min(ans, dist(b[i], g[mgg], r[mnrr]));
        }
    }

    cout << ans ln;
}

int main() {
    optimise
#ifdef _DEBUG
    freopen("IN.TXT", "r", stdin);
#else
    //freopen("unequal.in", "r", stdin);
    //freopen("unequal.out", "w", stdout);
#endif

    int t = 1;
    cin >> t;
    while(t--){
        solve();
    }
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <math.h>
#include <cstdlib>
#include <set>
#include <string>
#include <map>
#include <sstream>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <cmath>
#include <stack>

using namespace std;

typedef pair<int, int> pii;
typedef long long LL;
#define forn(i,n) for(int i=0;i<(n);++i)
#define forv(i,v) forn(i,v.size())

const int N = 20005;

LL distance(const vector<LL>& r, const vector<LL>& g, const vector<LL>& b, int sr, int sg, int sb) {
	return ((r[sr] - g[sg]) * (r[sr] - g[sg]) + (b[sb] - g[sg]) * (b[sb] - g[sg]) + (r[sr] - b[sb]) * (r[sr] - b[sb]));
}

LL check(const vector<LL>& r, const vector<LL>& g, const vector<LL>& b) {
	int rr = r.size(), gg = g.size(), bb = b.size();
	int sr = 0, sg = 0, sb = 0;
	while (sb < bb && (b[sb] < r[sr]|| b[sb] < g[sr])) sb++;
	LL locans = LLONG_MAX;
	while (sb < bb) {
		while ((sr < rr - 1 && r[sr + 1] <= b[sb]) || (sg < gg - 1 && g[sg + 1] <= b[sb])) {
			if (sr < rr - 1 && r[sr + 1] <= b[sb] && r[sr] <= g[sg]) sr++;
			else if (sg < gg - 1 && g[sg + 1] <= b[sb] && g[sg] <= r[sr]) sg++;
			else {
				while (sr < rr - 1 && r[sr + 1] <= b[sb]) {
					locans = min(locans, distance(r, g, b, sr, sg, sb));
					sr++;
				}
				while (sg < gg - 1 && g[sg + 1] <= b[sb]) {
					locans = min(locans, distance(r, g, b, sr, sg, sb));
					sg++;
				}
			}
		}
		locans = min(locans, distance(r, g, b, sr, sg, sb));
		sb++;
	}
	return locans;
}

void solve() {
	int nr, ng, nb;
	cin >> nr >> ng >> nb;
	vector<LL> r(nr), g(ng), b(nb);
	forn(i, nr) cin >> r[i];
	forn(i, ng) cin >> g[i];
	forn(i, nb) cin >> b[i];
	sort(r.begin(), r.end());
	sort(g.begin(), g.end());
	sort(b.begin(), b.end());
	LL ans = LLONG_MAX;
	ans = min(min(min(ans, check(r, g, b)), check(g, b, r)), check(b, r, g));
	cout << ans << endl;
}

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.precision(20);
#ifdef _MYMY_DEBUG
	freopen("input.txt", "rt", stdin); freopen("output.txt", "wt", stdout);
#endif

	int t;
	cin >> t;
	forn(i, t) solve();

	return 0;
}


#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <iomanip>
#include <fstream>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <list>
#include <functional>
//#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ve(a,b,c) vector <ll> a(b,c);
#define fo(a,b,c) for (int a = b; a < c; a++)
#define vec(a,b,c,d) vector <vector <int>> a(b, vector <int> (c,d));
#define all(a) a.begin(), a.end()
#define e  << endl;
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define cin2(a) scanf("%d",&a);
const ll INF = 1e9;

ll s(ll a){ return a * a;}
void f(vector <ll> &a, vector <ll> &b, vector <ll> &c, ll &otv){
    for(int x : a){
        auto y = lower_bound(all(b),x);
        auto z = upper_bound(all(c),x);
        if (y == b.end() || z == c.begin()) continue;
        z--;
        ll per = s(x - *y) + s(*y - *z) + s(*z - x);
        otv = min(otv, per);
    }
}
int main(){
    int t;
    cin >> t;
    while (t--) {
        int nr, ng, nb;
        cin >> nr >> ng >> nb;
        ve(r,nr,0);
        fo(i,0,nr) cin >> r[i];
        ve(g,ng,0);
        fo(i,0,ng) cin >> g[i];
        ve(b,nb,0);
        fo(i,0,nb) cin >> b[i];
        ll otv = 8e18;
        sort(all(r));
        sort(all(g));
        sort(all(b));
        f(r,g,b,otv);
        f(r,b,g,otv);
        f(b,r,b,otv);
        f(b,g,r,otv);
        f(g,r,b,otv);
        f(g,b,r,otv);
        cout << otv e
    }
}
/*

 */


#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <iomanip>
#include <fstream>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <list>
#include <functional>
//#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ve(a,b,c) vector <ll> a(b,c);
#define fo(a,b,c) for (int a = b; a < c; a++)
#define vec(a,b,c,d) vector <vector <int>> a(b, vector <int> (c,d));
#define all(a) a.begin(), a.end()
#define e  << endl;
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define cin2(a) scanf("%d",&a);
const ll INF = 1e9;

ll s(ll a){ return a * a;}
void f(vector <ll> &a, vector <ll> &b, vector <ll> &c, ll &otv){
    for(int x : a){
        auto y = lower_bound(all(b),x);
        auto z = upper_bound(all(c),x);
        if (y == b.end() || z == c.begin()) continue;
        z--;
        ll per = s(x - *y) + s(*y - *z) + s(*z - x);
        otv = min(otv, per);
    }
}
int main(){
    int t;
    cin >> t;
    while (t--) {
        int nr, ng, nb;
        cin >> nr >> ng >> nb;
        ve(r,nr,0);
        fo(i,0,nr) cin >> r[i];
        ve(g,ng,0);
        fo(i,0,ng) cin >> g[i];
        ve(b,nb,0);
        fo(i,0,nb) cin >> b[i];
        ll otv = 8e18;
        sort(all(r));
        sort(all(g));
        sort(all(b));
        f(r,g,b,otv);
        f(r,b,g,otv);
        f(b,r,g,otv);
        f(b,g,r,otv);
        f(g,r,b,otv);
        f(g,b,r,otv);
        cout << otv e
    }
}
/*

 */


#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<cstdio>
#include<string>
#include<vector>
#include<cstring>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<algorithm>
// #include<bits/stdc++.h>
#define INF 0x7f7f7f7f //2139062143
#define INF1 0x3f3f3f3f //1061109567
#define INF2 2147483647
#define llINF 9223372036854775807
#define pi 3.141592653589793//23846264338327950254
#define ft first
#define sd second
#define pb push_back
#define ll long long
#define vec vector<ll>
#define mat vector<vector<ll>>
//cout<<fixed<<setprecision(6)<<
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
//ifstream f1("/Users/wangzichao/Documents/wzc.in");
//ofstream f2("/Users/wangzichao/Documents/wzc.out");
//ios::sync_with_stdio(false);
//cin.tie(0);cout.tie(0);
using namespace std;
#define local
#ifdef local
#endif
const ll maxn=6e5+7;
const double eps=1e-10;
// #define int ll
// const ll mod=1e9+7;
#define STDIN freopen("in.txt","r",stdin); freopen("out.txt","w",stdout);//************************************
#define Quick ios::sync_with_stdio(false);cin.tie(NULL);

//  int qmi(int m, int k)
// {
//     int res = 1, t = m;
//     while (k)
//     {
//         if (k&1) res = res * t;
//         t = t * t;
//         k >>= 1;
//     }
//     return res;
// }
// signed main()
// {
// 	STDIN
// 	Quick
// 	int t; cin >> t;
// 	while (t--)
// 	{
// 		int x, n , m; cin >> x >> n >> m;
// 		for (int i = 1; i <= n; i++)
// 		{
// 			if (x > 20)
// 				x = x/2 + 10;
// 			else break;
// 		}
// 		x -= 10*m;
// 		if (x > 0) puts("NO");
// 		else puts("YES");
// 	}
// }
#define int ll
int value(int a, int b, int c)
{
	if (a== -1 || b == -1 || c == -1) return llINF;
	return (a-b)*(a-b) + (b-c)*(b-c) + (c-a)*(c-a);
}
int f(int a, int b1, int b2, int c1, int c2)
{
	return min(min(min(value(a,b1,c1),value(a,b1,c2)),value(a,b2,c1)),value(a,b2,c2));
	// int s[2] = {b1,b2};
	// int ss[2] = {c1,c2};
	// for (int i = 0; i < 2; i++)
	// {
	// 	for (int j = 0; j < 2; j++)
	// 	{
	// 		if ()
	// 	}
	// }
}
const int N = 1e5 + 10;

signed main(){
// 	STDIN
	int t; cin >> t;
	while (t--)
	{
		vector<int> a, b, c;
		int r, g, bb; scanf("%lld%lld%lld", &r, &g, &bb);
		ll tmp;
		for (int i = 0; i < r; i++ )
		{
			scanf("%lld", &tmp); a.push_back(tmp);
		}
		for (int i = 0; i < g; i++ )
		{
			scanf("%lld", &tmp); b.push_back(tmp);
		}
		for (int i = 0; i < bb; i++ )
		{
			scanf("%lld", &tmp); c.push_back(tmp);
		}
		sort(a.begin(), a.end()), sort(b.begin(), b.end()), sort(c.begin(), c.end());
		int minn = llINF;
		for (int i = 0; i < r; i++)
		{
			auto p = lower_bound(b.begin(), b.end(), a[i]);
			int b1 = -1, b2 = -1;
			if (p != b.end())
				b1 = *p;
			else b1 = *(p-1);
			if (p!=b.begin())
				b2 = *(p-1);
			p = lower_bound(c.begin(), c.end(), a[i]);
			int c1 = -1, c2 = -1;
			if (p != c.end())
				c1 = *p;
			else c1 = *(p-1);
			if (p!=c.begin())
				c2 = *(p-1);
			// cout << b1 << " " << b2 << " " << c1 << " " << c2 << endl;
			minn = min(minn, f(a[i],b1,b2,c1,c2));
			// cout << f(a[i],b1,b2,c1,c2) << endl;
		}
		for (int i = 0; i < g; i++)
		{
			auto p = lower_bound(a.begin(), a.end(), b[i]);
			int b1 = -1, b2 = -1;
			if (p != a.end())
				b1 = *p;
			else b1 = *(p-1);
			if (p!=a.begin())
				b2 = *(p-1);
			p = lower_bound(c.begin(), c.end(), a[i]);
			int c1 = -1, c2 = -1;
			if (p != c.end())
				c1 = *p;
			else c1 = *(p-1);
			if (p!=c.begin())
				c2 = *(p-1);
			// cout << b1 << " " << b2 << " " << c1 << " " << c2 << endl;
			minn = min(minn, f(b[i],b1,b2,c1,c2));
			// cout << f(a[i],b1,b2,c1,c2) << endl;
		}
		// cout << "*****************" << endl;
		printf("%lld\n", minn);
	}
	return 0;
}


#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<cstdio>
#include<string>
#include<vector>
#include<cstring>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<algorithm>
// #include<bits/stdc++.h>
#define INF 0x7f7f7f7f //2139062143
#define INF1 0x3f3f3f3f //1061109567
#define INF2 2147483647
#define llINF 9223372036854775807
#define pi 3.141592653589793//23846264338327950254
#define ft first
#define sd second
#define pb push_back
#define ll long long
#define vec vector<ll>
#define mat vector<vector<ll>>
//cout<<fixed<<setprecision(6)<<
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
//ifstream f1("/Users/wangzichao/Documents/wzc.in");
//ofstream f2("/Users/wangzichao/Documents/wzc.out");
//ios::sync_with_stdio(false);
//cin.tie(0);cout.tie(0);
using namespace std;
#define local
#ifdef local
#endif
const ll maxn=6e5+7;
const double eps=1e-10;
// #define int ll
// const ll mod=1e9+7;
#define STDIN freopen("in.txt","r",stdin); freopen("out.txt","w",stdout);//************************************
#define Quick ios::sync_with_stdio(false);cin.tie(NULL);

//  int qmi(int m, int k)
// {
//     int res = 1, t = m;
//     while (k)
//     {
//         if (k&1) res = res * t;
//         t = t * t;
//         k >>= 1;
//     }
//     return res;
// }
// signed main()
// {
// 	STDIN
// 	Quick
// 	int t; cin >> t;
// 	while (t--)
// 	{
// 		int x, n , m; cin >> x >> n >> m;
// 		for (int i = 1; i <= n; i++)
// 		{
// 			if (x > 20)
// 				x = x/2 + 10;
// 			else break;
// 		}
// 		x -= 10*m;
// 		if (x > 0) puts("NO");
// 		else puts("YES");
// 	}
// }
#define int ll
int value(int a, int b, int c)
{
	if (a== -1 || b == -1 || c == -1) return llINF;
	return (a-b)*(a-b) + (b-c)*(b-c) + (c-a)*(c-a);
}
int f(int a, int b1, int b2, int c1, int c2)
{
	return min(min(min(value(a,b1,c1),value(a,b1,c2)),value(a,b2,c1)),value(a,b2,c2));
	// int s[2] = {b1,b2};
	// int ss[2] = {c1,c2};
	// for (int i = 0; i < 2; i++)
	// {
	// 	for (int j = 0; j < 2; j++)
	// 	{
	// 		if ()
	// 	}
	// }
}
const int N = 1e5 + 10;

signed main(){
// 	STDIN
	int t; cin >> t;
	while (t--)
	{
		vector<int> a, b, c;
		int r, g, bb; scanf("%lld%lld%lld", &r, &g, &bb);
		ll tmp;
		for (int i = 0; i < r; i++ )
		{
			scanf("%lld", &tmp); a.push_back(tmp);
		}
		for (int i = 0; i < g; i++ )
		{
			scanf("%lld", &tmp); b.push_back(tmp);
		}
		for (int i = 0; i < bb; i++ )
		{
			scanf("%lld", &tmp); c.push_back(tmp);
		}
		sort(a.begin(), a.end()), sort(b.begin(), b.end()), sort(c.begin(), c.end());
		int minn = llINF;
		for (int i = 0; i < r; i++)
		{
			auto p = lower_bound(b.begin(), b.end(), a[i]);
			int b1 = -1, b2 = -1;
			if (p != b.end())
				b1 = *p;
			else b1 = *(p-1);
			if (p!=b.begin())
				b2 = *(p-1);
			p = lower_bound(c.begin(), c.end(), a[i]);
			int c1 = -1, c2 = -1;
			if (p != c.end())
				c1 = *p;
			else c1 = *(p-1);
			if (p!=c.begin())
				c2 = *(p-1);
			// cout << b1 << " " << b2 << " " << c1 << " " << c2 << endl;
			minn = min(minn, f(a[i],b1,b2,c1,c2));
			// cout << f(a[i],b1,b2,c1,c2) << endl;
		}
		for (int i = 0; i < g; i++)
		{
			auto p = lower_bound(a.begin(), a.end(), b[i]);
			int b1 = -1, b2 = -1;
			if (p != a.end())
				b1 = *p;
			else b1 = *(p-1);
			if (p!=a.begin())
				b2 = *(p-1);
			p = lower_bound(c.begin(), c.end(), b[i]);
			int c1 = -1, c2 = -1;
			if (p != c.end())
				c1 = *p;
			else c1 = *(p-1);
			if (p!=c.begin())
				c2 = *(p-1);
			// cout << b1 << " " << b2 << " " << c1 << " " << c2 << endl;
			minn = min(minn, f(b[i],b1,b2,c1,c2));
			// cout << f(a[i],b1,b2,c1,c2) << endl;
		}
		for (int i = 0; i < bb; i++)
		{
			auto p = lower_bound(a.begin(), a.end(), c[i]);
			int b1 = -1, b2 = -1;
			if (p != a.end())
				b1 = *p;
			else b1 = *(p-1);
			if (p!=a.begin())
				b2 = *(p-1);
			p = lower_bound(b.begin(), b.end(), c[i]);
			int c1 = -1, c2 = -1;
			if (p != b.end())
				c1 = *p;
			else c1 = *(p-1);
			if (p!=b.begin())
				c2 = *(p-1);
			// cout << b1 << " " << b2 << " " << c1 << " " << c2 << endl;
			minn = min(minn, f(c[i],b1,b2,c1,c2));
			// cout << f(a[i],b1,b2,c1,c2) << endl;
		}
		// cout << "*****************" << endl;
		printf("%lld\n", minn);
	}
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

using ull = unsigned long long;

inline ull sqr(ull x) {
	return x * x;
}

inline ull calc_f(int x, int y, int z) {
	return sqr(x - y) + sqr(x - z) + sqr(y - z);
}

void processTest()
{
	int nr, ng, nb;
	cin >> nr >> ng >> nb;
	vector<int> r(nr), g(ng), b(nb);
	for (auto& rv : r) {
		cin >> rv;
	}
	for (auto& rv : g) {
		cin >> rv;
	}
	for (auto& rv : b) {
		cin >> rv;
	}

	sort(begin(r), end(r));
	sort(begin(g), end(g));
	sort(begin(b), end(b));

	int br = 0, bg = 0, bb = 0;

	ull curValue = calc_f(r[br],g[bg], b[bb]);

	nr--;
	ng--;
	nb--;

	while (true) {
		if (br == nr && bg == ng && bb == nb) {
			break;
		}
		int next_g = bg != ng ? bg + 1 : -1;
		int next_b = bb != nb ? bb + 1 : -1;
		int next_r = br != nr ? br + 1 : -1;

		ull ng, nb, nr;
		ull next_min = 0;
		bool x = true;

		bool move_g = false, move_r = false, move_b = false;

		if (next_g != -1) {
			ng = calc_f(r[br], g[next_g], b[bb]);
			if (x) {
				next_min = ng;
				x = false;
				move_g = true;
			}
		}
		if (next_b != -1) {
			nb = calc_f(r[br], g[bg], b[next_b]);
			if (x) {
				next_min = nb;
				x = false;
				move_b = true;
			}
			else {
				if (nb < next_min) {
					next_min = nb;
					move_b = true;
				}
			}
		}
		if (next_r != -1) {
			nr = calc_f(r[next_r], g[bg], b[bb]);
			if (x) {
				next_min = nr;
				x = false;
				move_r = true;
			}
			else {
				if (nr < next_min) {
					next_min = nr;
					move_r = true;
				}
			}
		}
		curValue = min(curValue, next_min);
		if (move_r) {
			br++;
		}
		else if (move_b) {
			bb++;
		}
		else {
			bg++;
		}
	}

	cout << curValue << "\n";
}

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.precision(20);
	int tests_count;
	cin >> tests_count;
	for (int i = 0; i < tests_count; i++) {
		processTest();
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<fstream>
#include<algorithm>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<cstring>
#include<vector>
using namespace std;
#define for1(i,n) for(int i=1;i<=(int)n;i++)
#define for0(i,n) for(int i=0;i<=(int)n;i++)
#define forn(i,n) for(int i=n;i>=1;i--)
#define fo(i,x,y) for(int i=x;i<=(int)y;i++)
#define fr(i,x,y) for(int i=x;i>=(int)y;i--)
#define pb push_back
#define mp make_pair
#define LL long long
#define ld long double
const LL Mod=1000*1000*1000+7;
//1
//2
//3
LL a[300002][5];
LL b[300002][5];
LL ma=(LL)((LL)2*1000*1000*1000*1000*1000*1000);
LL fun(LL a,LL b,LL c)
{
    //hihshi mec
    if(a==-1 || b==-1 || c==-1)
        return ma;
    return ((LL)(a-b)*(a-b)+(LL)(a-c)*(a-c)+(LL)(b-c)*(b-c));
}
int main()
{
    int t;
    cin>>t;
    for1(j,t)
    {
        ///hishi prinf
        int r1,g1,b1;
        scanf("%d%d%d",&r1,&g1,&b1);
        vector<pair<int,LL> > v;
        LL x;
        for1(i,r1)
        {
            scanf("%lld",&x);
            v.pb(make_pair(x,1));
        }
        for1(i,g1)
        {
            scanf("%lld",&x);
            v.pb(make_pair(x,2));
        }
        for1(i,b1)
        {
            scanf("%lld",&x);
            v.pb(make_pair(x,3));
        }
        sort(v.begin(),v.end());
        LL r[4];
        for1(i,3)
            r[i]=-1;
        for0(i,v.size()-1)
        {
            int j;
            for(j=i;j<=v.size()-1;j++)
            {
                r[v[j].second]=v[j].first;
                if(j==(v.size()-1) || v[j].first!=v[j+1].first)
                    break;
            }
            fo(z,i,j)
                for1(k,3)
                    a[z][k]=r[k];
            i=j;
        }
        for1(i,3)
            r[i]=-1;
        for(int i=v.size()-1;i>=0;i--)
        {
            int j;
            for(j=i;j>=0;j--)
            {
                r[v[j].second]=v[j].first;
                if(j==0 || v[j].first!=v[j-1].first)
                    break;
            }
            for(int z=i;z>=j;z--)
                for1(k,3)
                    b[z][k]=r[k];
            i=j;
        }
        //hishi mec
        LL ANS=ma;
        for0(i,v.size()-1)
        {
            int guyn=v[i].second;
            LL pos=v[i].first;
            int u=(guyn+1);
            if(u==4)
                u=1;
            int v=(guyn-1);
            if(v==0)
                v=3;
            ANS=min(ANS,fun(a[i][u],b[i][v],pos));
            ANS=min(ANS,fun(a[i][v],b[i][u],pos));
        }
        printf("%lld \n",ANS);
    }
    return 0;
}
// 1000000000


#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <bitset>
#include <time.h>
#include <map>
#include <stack>
#include <unordered_map>

using namespace std;

void boostIO() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
}

const int maxn = 1e5 + 5;
const int unsigned long long inf = 1999999996000000002;

int t;
int n[3];
int a[3][maxn];

unsigned long long get(unsigned long long x, unsigned long long y, unsigned long long z) {
	return (x - y) * (x - y) + (x - z) * (x - z) + (y - z) * (y - z);
}

unsigned long long solve(int i, int j, int k) {
	unsigned long long ans = inf;
	for (int c = 0; c < n[i]; ++c) {
		int idx1 = lower_bound(a[j], a[j] + n[j], a[i][c]) - a[j];
		if (idx1 == n[j]) idx1 = n[j] - 1;
		else if (idx1 == 0 && a[j][idx1] > a[i][c]) continue;
		else if (idx1 > 0 && a[j][idx1] > a[i][c]) --idx1;
		int idx2 = lower_bound(a[k], a[k] + n[k], a[i][c]) - a[k];
		if (idx2 == n[k]) return ans;
		ans = min(ans, get(a[j][idx1], a[k][idx2], a[i][c]));
	}
	return ans;
}

int main()
{
	boostIO();
	cin >> t;

	while (t--) {
		unsigned long long ans = inf;
		for (int i = 0; i < 3; ++i) cin >> n[i];
		for (int i = 0; i < 3; ++i) {
			for (int j = 0; j < n[i]; ++j) cin >> a[i][j];
			sort(a[i], a[i] + n[i]);
		}
		vector<int> perm = { 0, 1, 2 };
		do {
			ans = min(ans, solve(perm[0], perm[1], perm[2]));
		} while (next_permutation(perm.begin(), perm.end()));
		cout << ans << '\n';

	}

	return 0;
}


#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <utility>
#include <set>
#include <algorithm>
#include <climits>

using namespace std;

long long Lol(std::multiset<int>& r_v, std::multiset<int>& b_v, std::multiset<int>& g_v) {
  long long x = 0;
  long long y = 0;
  long long z = 0;
  long long sum_delta = 0;
  long long delta = 2e15;
  for (auto it : r_v) {
    auto jit = b_v.lower_bound(it);
    auto kit = b_v.upper_bound(it);
    if (kit == b_v.end()) {
      kit = --b_v.end();
    }
    if (jit == b_v.end()) {
      jit = --b_v.end();
    }
    if (std::abs(*jit - it) < delta) {
      delta = std::abs(*jit - it);
      x = it;
      y = *jit;
    }
    if (std::abs(*kit - it) < delta) {
      delta = std::abs(*kit - it);
      x = it;
      y = *kit;
    }
  }
  auto lit = g_v.lower_bound(y);
  auto uit = g_v.upper_bound(y);
  if (lit == g_v.end()) {
    --lit;
  }
  if (uit == g_v.end()) {
    --uit;
  }
  return std::min((x - y) * (x - y) + (x - *lit) * (x - *lit) + (*lit - y) * (*lit - y),
                  (x - y) * (x - y) + (x - *uit) * (x - *uit) + (*uit - y) * (*uit - y));
}

void Kek() {
  int r, b, g;
  std::cin >> r >> b >> g;
  std::vector<int> r_v(r, 0);
  std::vector<int> b_v(b, 0);
  std::vector<int> g_v(g, 0);
  int n;

  for (int i = 0; i < r; ++i) {
    std::cin >> r_v[i];
  }
  for (int i = 0; i < b; ++i) {
    std::cin >> b_v[i];
  }
  for (int i = 0; i < g; ++i) {
    std::cin >> g_v[i];
  }
  long long sum_delta = 9223372036854775807;
  std::sort(r_v.begin(), r_v.end());
  std::sort(b_v.begin(), b_v.end());
  std::sort(g_v.begin(), g_v.end());
  //r_v.push_back(sum_delta);
  //b_v.push_back(sum_delta);
  //g_v.push_back(sum_delta);
  //sum_delta = std::min(Lol(r_v, b_v, g_v), sum_delta);
  //sum_delta = std::min(Lol(r_v, g_v, b_v), sum_delta);
  //sum_delta = std::min(Lol(b_v, r_v, g_v), sum_delta);
  //sum_delta = std::min(Lol(b_v, g_v, r_v), sum_delta);
  //sum_delta = std::min(Lol(g_v, b_v, r_v), sum_delta);
  //sum_delta = std::min(Lol(g_v, r_v, b_v), sum_delta);
  --r;
  --b;
  --g;

  int i = 0;
  int j = 0;
  int k = 0;
  do {
    long long x = r_v[i];
    long long y = b_v[j];
    long long z = g_v[k];
    sum_delta = std::min(sum_delta, (x - y) * (x - y) + (x - z) * (x - z) + (z - y) * (z - y));
    long long min = std::min(x, std::min(y, z));
    if (i == r && j == b) {
      ++k;
    } else if (i == r && k == g) {
      ++j;
    } else if (j == b && k == g) {
      ++i;
    } else if (i == r) {
      if (y == std::min(y, z)) {
        ++j;
      } else {
        ++k;
      }
    } else if (j == b) {
      if (x == std::min(x, z)) {
        ++i;
      } else {
        ++k;
      }
    } else if (k == g) {
      if (y == std::min(y, x)) {
        ++j;
      } else {
        ++i;
      }
    } else {
      if (x == min && i != r) {
        ++i;
      } else if (y == min && j != b) {
        ++j;
      } else {
        ++k;
      }
    }
  } while (i < r || j < b || k < g);
  std::cout << sum_delta << '\n';
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cout.precision(10);
  cout << fixed;
  int t;
  std::cin >> t;
  for (int i = 0; i < t; ++i) {
    if (i == 1) {
      int h = 0;
    }
    Kek();
  }
}


#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <utility>
#include <set>
#include <algorithm>
#include <climits>

using namespace std;

const long long inf = 9223372036854775807;

void Kek() {
  int r, b, g;
  std::cin >> r >> b >> g;
  std::vector<long long> r_v(r, 0);
  std::vector<long long> b_v(b, 0);
  std::vector<long long> g_v(g, 0);
  int n;

  for (int i = 0; i < r; ++i) {
    std::cin >> r_v[i];
  }
  for (int i = 0; i < b; ++i) {
    std::cin >> b_v[i];
  }
  for (int i = 0; i < g; ++i) {
    std::cin >> g_v[i];
  }
  long long sum_delta = 9223372036854775807;
  std::sort(r_v.begin(), r_v.end());
  std::sort(b_v.begin(), b_v.end());
  std::sort(g_v.begin(), g_v.end());
  r_v.push_back(2e9);
  b_v.push_back(2e9);
  g_v.push_back(2e9);

  int i = 0;
  int j = 0;
  int k = 0;
  do {
    long long x = r_v[i];
    long long y = b_v[j];
    long long z = g_v[k];
    sum_delta = std::min(sum_delta, (x - y) * (x - y) + (x - z) * (x - z) + (z - y) * (z - y));
    long long n_x = -1;
    long long n_y = -1;
    long long n_z = -1;
    if (i == r) {
      n_x = inf;
    } else {
      n_x = (r_v[i + 1] - y) * (r_v[i + 1] - y) + (r_v[i + 1] - z) * (r_v[i + 1] - z) + (z - y) * (z - y);
    }
    if (j == b) {
      n_y = inf;
    } else {
      n_y = (x - b_v[j + 1]) * (x - b_v[j + 1]) + (x - z) * (x - z) + (z - b_v[j + 1]) * (z - b_v[j + 1]);
    }
    if (k == g) {
      n_z = inf;
    } else {
      n_z = (x - y) * (x - y) + (x - g_v[k + 1]) * (x - g_v[k + 1]) + (g_v[k + 1] - y) * (g_v[k + 1] - y);
    }
    long long min = std::min(n_x, std::min(n_y, n_z));
    if (n_x == min) {
      ++i;
    } else if (n_y == min) {
      ++j;
    } else {
      ++k;
    }
  } while (i < r || j < b || k < g);
  std::cout << sum_delta << '\n';
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cout.precision(10);
  cout << fixed;
  int t;
  std::cin >> t;
  for (int i = 0; i < t; ++i) {
    if (i == 1) {
      int h = 0;
    }
    Kek();
  }
}


#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <utility>
#include <set>
#include <algorithm>
#include <climits>

using namespace std;

long long Lol(std::multiset<int>& r_v, std::multiset<int>& b_v, std::multiset<int>& g_v) {
  long long x = 0;
  long long y = 0;
  long long z = 0;
  long long sum_delta = 0;
  long long delta = 2e15;
  for (auto it : r_v) {
    auto jit = b_v.lower_bound(it);
    auto kit = b_v.upper_bound(it);
    if (kit == b_v.end()) {
      kit = --b_v.end();
    }
    if (jit == b_v.end()) {
      jit = --b_v.end();
    }
    if (std::abs(*jit - it) < delta) {
      delta = std::abs(*jit - it);
      x = it;
      y = *jit;
    }
    if (std::abs(*kit - it) < delta) {
      delta = std::abs(*kit - it);
      x = it;
      y = *kit;
    }
  }
  auto lit = g_v.lower_bound(y);
  auto uit = g_v.upper_bound(y);
  if (lit == g_v.end()) {
    --lit;
  }
  if (uit == g_v.end()) {
    --uit;
  }
  return std::min((x - y) * (x - y) + (x - *lit) * (x - *lit) + (*lit - y) * (*lit - y),
                  (x - y) * (x - y) + (x - *uit) * (x - *uit) + (*uit - y) * (*uit - y));
}

void Kek() {
  int r, b, g;
  std::cin >> r >> b >> g;
  std::multiset<int> r_v;
  std::multiset<int> b_v;
  std::multiset<int> g_v;
  int n;
  if (r == b && b == g) {
    int f = 0;
  }
  for (int i = 0; i < r; ++i) {
    std::cin >> n;
    r_v.insert(n);
  }
  for (int i = 0; i < b; ++i) {
    std::cin >> n;
    b_v.insert(n);
  }
  for (int i = 0; i < g; ++i) {
    std::cin >> n;
    g_v.insert(n);
  }
  long long sum_delta = 9223372036854775807;
  sum_delta = std::min(Lol(r_v, b_v, g_v), sum_delta);
  sum_delta = std::min(Lol(r_v, g_v, b_v), sum_delta);
  sum_delta = std::min(Lol(b_v, r_v, g_v), sum_delta);
  sum_delta = std::min(Lol(b_v, g_v, r_v), sum_delta);
  sum_delta = std::min(Lol(g_v, b_v, r_v), sum_delta);
  sum_delta = std::min(Lol(g_v, r_v, b_v), sum_delta);
  std::cout << sum_delta << '\n';
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cout.precision(10);
  cout << fixed;
  int t;
  std::cin >> t;
  for (int i = 0; i < t; ++i) {
    if (i == t - 1) {
      int h = 0;
    }
    Kek();
  }
}


#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <utility>
#include <set>
#include <algorithm>
#include <climits>

using namespace std;

long long Lol(std::multiset<int>& r_v, std::multiset<int>& b_v, std::multiset<int>& g_v) {
  long long x = 0;
  long long y = 0;
  long long z = 0;
  long long sum_delta = 0;
  long long delta = 2e15;
  for (auto it : r_v) {
    auto jit = b_v.lower_bound(it);
    auto kit = b_v.upper_bound(it);
    if (kit == b_v.end()) {
      kit = --b_v.end();
    }
    if (jit == b_v.end()) {
      jit = --b_v.end();
    }
    if (std::abs(*jit - it) < delta) {
      delta = std::abs(*jit - it);
      x = it;
      y = *jit;
    }
    if (std::abs(*kit - it) < delta) {
      delta = std::abs(*kit - it);
      x = it;
      y = *kit;
    }
  }
  auto lit = g_v.lower_bound(y);
  auto uit = g_v.upper_bound(y);
  if (lit == g_v.end()) {
    --lit;
  }
  if (uit == g_v.end()) {
    --uit;
  }
  return std::min((x - y) * (x - y) + (x - *lit) * (x - *lit) + (*lit - y) * (*lit - y),
                  (x - y) * (x - y) + (x - *uit) * (x - *uit) + (*uit - y) * (*uit - y));
}

void Kek() {
  int r, b, g;
  std::cin >> r >> b >> g;
  std::multiset<int> r_v;
  std::multiset<int> b_v;
  std::multiset<int> g_v;
  int n;
  if (r == b && b == g) {
    int f = 0;
  }
  for (int i = 0; i < r; ++i) {
    std::cin >> n;
    r_v.insert(n);
  }
  for (int i = 0; i < b; ++i) {
    std::cin >> n;
    b_v.insert(n);
  }
  for (int i = 0; i < g; ++i) {
    std::cin >> n;
    g_v.insert(n);
  }
  long long sum_delta = LONG_LONG_MAX;
  sum_delta = std::min(Lol(r_v, b_v, g_v), sum_delta);
  sum_delta = std::min(Lol(r_v, g_v, b_v), sum_delta);
  sum_delta = std::min(Lol(b_v, r_v, g_v), sum_delta);
  sum_delta = std::min(Lol(b_v, g_v, r_v), sum_delta);
  sum_delta = std::min(Lol(g_v, b_v, r_v), sum_delta);
  sum_delta = std::min(Lol(g_v, r_v, b_v), sum_delta);
  std::cout << sum_delta << '\n';
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cout.precision(10);
  cout << fixed;
  int t;
  std::cin >> t;
  for (int i = 0; i < t; ++i) {
    if (i == t - 1) {
      int h = 0;
    }
    Kek();
  }
}


#include <iostream>
#include <sstream>
#include <cmath>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <string>
#include <set>
#include <ctime>
#include <algorithm>
using namespace std;

long long int f(int x, int y, int z) {
	long long int res = 0;
	res += (x - y) * (long long int)(x - y);
	res += (y - z) * (long long int)(y - z);
	res += (z - x) * (long long int)(z - x);
	return res;
}

long long int search(vector<int> &a, vector<int> &b, vector<int> &c, long long int ans) {
	int na = a.size(), nb = b.size(), nc = c.size();
	int i1, i2, i3;
	i1 = i2 = i3 = 0;

	while (i1 < na && i2 < nb) {
		int right = nc - 1;
		int left = 0;

		while (right - left > 1) {
			i3 = (left + right) / 2;
			if (c[i3] <= (a[i1] + b[i2]) / 2)
				left = i3;
			else
				right = i3;
		}
		ans = min(ans, f(a[i1], b[i2], c[left]));
		ans = min(ans, f(a[i1], b[i2], c[right]));
		if (i1 == na - 1)
			i2++;
		else if (i2 == nb - 1)
			i1++;
		else if (a[i1] <= b[i2])
			i1++;
		else if (b[i2] <= a[i1])
			i2++;
	}
	return ans;
}

int main()
{
	int t;
	cin >> t;

	while (t--) {
		int nr, ng, nb;
		long long int ans;
		cin >> nr >> ng >> nb;
		vector<int> r(nr), g(ng), b(nb);

		for (int i = 0; i < nr; i++) {
			cin >> r[i];
		}
		for (int i = 0; i < ng; i++) {
			cin >> g[i];
		}
		for (int i = 0; i < nb; i++) {
			cin >> b[i];
		}
		sort(r.begin(), r.end());
		sort(g.begin(), g.end());
		sort(b.begin(), b.end());

		ans = f(r[0], g[0], b[0]);
		ans = min(ans, search(r, g, b, ans));
		ans = min(ans, search(r, b, g, ans));
		ans = min(ans, search(g, b, r, ans));

		cout << ans << endl;
	}

	return 0;
}


#include <iostream>
#include <sstream>
#include <cmath>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <string>
#include <set>
#include <ctime>
#include <algorithm>
using namespace std;

long long int f(int x, int y, int z) {
	long long int res = 0;
	res += (x - y) * (long long int)(x - y);
	res += (y - z) * (long long int)(y - z);
	res += (z - x) * (long long int)(z - x);
	return res;
}

int main()
{
	int t;
	cin >> t;

	while (t--) {
		int nr, ng, nb;
		int i1, i2, i3;
		long long int ans;
		cin >> nr >> ng >> nb;
		vector<int> r(nr), g(ng), b(nb);

		for (int i = 0; i < nr; i++) {
			cin >> r[i];
		}
		for (int i = 0; i < ng; i++) {
			cin >> g[i];
		}
		for (int i = 0; i < nb; i++) {
			cin >> b[i];
		}
		sort(r.begin(), r.end());
		sort(g.begin(), g.end());
		sort(b.begin(), b.end());

		i1 = i2 = i3 = 0;
		ans = f(r[i1], g[i2], b[i3]);
		while (i1 < nr && i2 < ng) {
			int right = nb - 1;
			int left = 0;

			while (right - left > 1) {
				i3 = (left + right) / 2;
				if (b[i3] <= (r[i1] + g[i2]) / 2)
					left = i3;
				else
					right = i3;
			}
			ans = min(ans, f(r[i1], g[i2], b[left]));
			ans = min(ans, f(r[i1], g[i2], b[right]));
			if (i1 == nr - 1)
				i2++;
			else if (i2 == ng - 1)
				i1++;
			else if (r[i1] <= g[i2])
				i1++;
			else if (g[i2] <= r[i1])
				i2++;
		}
		cout << ans << endl;
	}

	return 0;
}


#include <iostream>
#include <sstream>
#include <cmath>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <string>
#include <set>
#include <ctime>
#include <algorithm>
using namespace std;

long long int f(int x, int y, int z) {
	long long int res = 0;
	res += (x - y) * (long long int)(x - y);
	res += (y - z) * (long long int)(y - z);
	res += (z - x) * (long long int)(z - x);
	return res;
}

int main()
{
	int t;
	cin >> t;

	while (t--) {
		int nr, ng, nb;
		int i1, i2, i3;
		bool f1, f2, f3;
		long long int ans;
		cin >> nr >> ng >> nb;
		vector<int> r(nr), g(ng), b(nb);

		for (int i = 0; i < nr; i++) {
			cin >> r[i];
		}
		for (int i = 0; i < ng; i++) {
			cin >> g[i];
		}
		for (int i = 0; i < nb; i++) {
			cin >> b[i];
		}
		sort(r.begin(), r.end());
		sort(g.begin(), g.end());
		sort(b.begin(), b.end());

		i1 = i2 = i3 = 0;
		f1 = f2 = f3 = true;
		ans = f(r[i1], g[i2], b[i3]);
		while (i1 < nr - 1 || i2 < ng - 1 || i3 < nb - 1) {
			if ((r[i1] <= g[i2] || !f2) && (r[i1] <= b[i3] || !f3) && f1)
				i1++;
			else if ((g[i2] <= r[i1] || !f1) && (g[i2] <= b[i3] || !f3) && f2)
				i2++;
			else if ((b[i3] <= r[i1] || !f1) && (b[i3] <= g[i2] || !f2) && f3)
				i3++;
			if (i1 >= nr - 1)
				f1 = false;
			if (i2 >= ng - 1)
				f2 = false;
			if (i3 >= nb - 1)
				f3 = false;
			ans = min(ans, f(r[i1], g[i2], b[i3]));
		}
		cout << ans << endl;
	}

	return 0;
}


#pragma warning(disable : 4996)
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>

	long long min = 100000000;

long long sqr(int x) {
	return 1ll* x * x;
}

void solve(std::vector<int> a, std::vector<int> b, std::vector<int> c) {
	long long ans=INT64_MAX;
	for (auto x:a) {
		auto y = std::lower_bound(b.begin(), b.end(), x);
		auto z = std::upper_bound(c.begin(), c.end(), x);
		if (y == b.end() || z == c.begin()) continue;
		z--;
		min = std::min(min, sqr(x - *y) + sqr(*y - *z) + sqr(*z - x));
	}
}

int main(){
	int tests, nr, ng, nb;
	long long tmp;

	std::vector<int>g;
	std::vector<int>r;
	std::vector<int>b;

		scanf("%d", &tests);
		for (int i = 0; i < tests; i++){
			min = INT64_MAX-1;
			scanf("%d %d %d", &nr, &ng, &nb);
			r.clear();
			g.clear();
			b.clear();
			for (unsigned long long i = 0; i < nr; i++) {
				scanf("%d", &tmp);
				r.push_back(tmp);
			}
			std::sort(r.begin(), r.end());
			for (unsigned long long i = 0; i < ng; i++) {
				scanf("%d", &tmp);
				g.push_back( tmp);
			}
			std::sort(g.begin(), g.end());
			for (unsigned long long i = 0; i < nb; i++) {
				scanf("%d", &tmp);
				b.push_back( tmp);
			}
			std::sort(b.begin(), b.end());

  			solve(r, g, b);
			solve(r, b, g);
			solve(g, r, b);
			solve(g, b, r);
			solve(b, g, r);
			solve(b, r, g);

			std::cout << min<<"\n\n";

		}
		return 0;
}


#pragma warning(disable : 4996)
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>

std::vector<std::pair<long long, int>>wng;
long long solve(int a, int b,int c) {
	int first, second, third;
	long long na, nb, nc;
		long long x=INT64_MAX;

	for (int i = 0; i < wng.size(); i++){
		if (wng[i].second != a)
			continue;
		for (second = i; second < wng.size(); second++){
			if (wng[second].second == b) {
				third = second;
				for (third = second; third < wng.size() && wng[third].second != c; third++)
				{
				}
				if (third == wng.size())
					break;
				na = (wng[i].first - wng[second].first) * (wng[i].first - wng[second].first);
				nb = (wng[i].first - wng[third].first) * (wng[i].first - wng[third].first);
				nc = (wng[third].first - wng[second].first) * (wng[third].first - wng[second].first);
				x = std::min(x, na + nb + nc);
			}
		}
	}
	return x;
}

int main(){
	int tests, nr, ng, nb;
	long long tmp;
	long long min = 100000000;
		scanf("%d", &tests);
		for (int i = 0; i < tests; i++){
			min = INT64_MAX-1;
			scanf("%d %d %d", &nr, &ng, &nb);
			wng.clear();
			for (unsigned long long i = 0; i < nr; i++) {
				scanf("%lld", &tmp);
				wng.push_back({ tmp,0 });
			}
			for (unsigned long long i = 0; i < ng; i++) {
				scanf("%lld", &tmp);
				wng.push_back({ tmp, 1 });
			}
			for (unsigned long long i = 0; i < nb; i++) {
				scanf("%lld", &tmp);
				wng.push_back({ tmp,2 });
			}
			std::sort(wng.begin(), wng.end());
			min = solve(0, 1, 2);
			min = std::min(min, solve(0, 2, 1));
			min = std::min(min, solve(1, 0, 2));
			min = std::min(min, solve(1, 2, 0));
			min = std::min(min, solve(2, 0, 1));
			min = std::min(min, solve(2, 1, 0));

 			printf("%lld\n\n", min);
		}

}


#include<cstdio>
#include<cstring>
#include<cmath>
#include<queue>
#include<algorithm>
#include<map>
#include<vector>
#define ll long long
using namespace std;
ll a[100010];
ll b[100010];
ll c[100010];

int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		int n,m,k;
		ll minn=5000000000000000000;
		scanf("%d%d%d",&n,&m,&k);
		map<ll,int> mp1,mp2,mp3;
		int nn=0,mm=0,kk=0;
		for(int i=0;i<n;i++)
		{
			ll x;
			scanf("%lld",&x);
			if(mp1[x]==0)
			{
				mp1[x]=1;
				a[nn++]=x;
			}
		}
		for(int i=0;i<m;i++)
		{
			ll x;
			scanf("%lld",&x);
			if(mp2[x]==0)
			{
				mp2[x]=1;
				b[mm++]=x;
			}
		}
		for(int i=0;i<k;i++)
		{
			ll x;
			scanf("%lld",&x);
			if(mp3[x]==0)
			{
				mp3[x]=1;
				c[kk++]=x;
			}
		}
		sort(a,a+nn);
		sort(b,b+mm);
		sort(c,c+kk);

		for(int i=0;i<nn;i++)
		{
			ll x=a[i];
			int pos=lower_bound(b,b+mm,x)-b;
			if(pos==mm)
			{
				pos--;
			}
			for(int j=pos-1;j<=pos+1;j++)
			{
				if(j<0||j>=mm)
				{
					continue;
				}
				ll y=b[j];
				int pos2=lower_bound(c,c+kk,y)-c;
				if(pos2==kk)
				{
					pos2--;
				}
				for(int f=pos2-1;f<=pos2+1;f++)
				{
					if(f<0||f>=kk)
					{
						continue;
					}
					ll z=c[f];
					//printf("%lld %lld %lld\n",x,y,z);
					minn=min(minn,(x-y)*(x-y)+(x-z)*(x-z)+(y-z)*(y-z));
				}
			}
		}
		printf("%lld\n",minn);
	}
}


#include<cstdio>
#include<cstring>
#include<cmath>
#include<queue>
#include<algorithm>
#include<map>
#include<vector>
#define ll long long
using namespace std;
ll a[100010];
ll b[100010];
ll c[100010];

int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		int n,m,k;
		ll minn=5000000000000000000;
		scanf("%d%d%d",&n,&m,&k);
		map<ll,int> mp1,mp2,mp3;
		int nn=0,mm=0,kk=0;
		for(int i=0;i<n;i++)
		{
			ll x;
			scanf("%lld",&x);
			if(mp1[x]==0)
			{
				mp1[x]=1;
				a[nn++]=x;
			}
		}
		for(int i=0;i<m;i++)
		{
			ll x;
			scanf("%lld",&x);
			if(mp2[x]==0)
			{
				mp2[x]=1;
				b[mm++]=x;
			}
		}
		for(int i=0;i<k;i++)
		{
			ll x;
			scanf("%lld",&x);
			if(mp3[x]==0)
			{
				mp3[x]=1;
				c[kk++]=x;
			}
		}
		sort(a,a+nn);
		sort(b,b+mm);
		sort(c,c+kk);

		for(int i=0;i<nn;i++)
		{
			ll x=a[i];
			int pos=lower_bound(b,b+mm,x)-b;
			if(pos==mm)
			{
				pos--;
			}
			for(int j=pos-1;j<=pos+1;j++)
			{
				if(j<0||j>=mm)
				{
					continue;
				}
				ll y=b[j];
				int pos2=lower_bound(c,c+kk,y)-c;
				if(pos2==kk)
				{
					pos2--;
				}
				for(int f=pos2-1;f<=pos2+1;f++)
				{
					if(f<0||f>=kk)
					{
						continue;
					}
					ll z=c[f];
					//printf("%lld %lld %lld\n",x,y,z);
					minn=min(minn,(x-y)*(x-y)+(x-z)*(x-z)+(y-z)*(y-z));
				}
			}

			//oooooooooooooooooooooo
			int pos1=lower_bound(c,c+kk,x)-c;
			if(pos1==kk)
			{
				pos1--;
			}
			for(int j=pos1-1;j<=pos1+1;j++)
			{
				if(j<0||j>=kk)
				{
					continue;
				}
				ll y=c[j];
				int pos3=lower_bound(b,b+mm,y)-b;
				if(pos3==mm)
				{
					pos3--;
				}
				for(int f=pos3-1;f<=pos3+1;f++)
				{
					if(f<0||f>=mm)
					{
						continue;
					}
					ll z=b[f];
					//printf("%lld %lld %lld\n",x,y,z);
					minn=min(minn,(x-y)*(x-y)+(x-z)*(x-z)+(y-z)*(y-z));
				}
			}
		}

		//uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu
		for(int i=0;i<mm;i++)
		{
			ll x=b[i];
			int pos=lower_bound(c,c+kk,x)-c;
			if(pos==kk)
			{
				pos--;
			}
			for(int j=pos-1;j<=pos+1;j++)
			{
				if(j<0||j>=kk)
				{
					continue;
				}
				ll y=c[j];
				int pos2=lower_bound(a,a+nn,y)-a;
				if(pos2==nn)
				{
					pos2--;
				}
				for(int f=pos2-1;f<=pos2+1;f++)
				{
					if(f<0||f>=nn)
					{
						continue;
					}
					ll z=a[f];
					//printf("%lld %lld %lld\n",x,y,z);
					minn=min(minn,(x-y)*(x-y)+(x-z)*(x-z)+(y-z)*(y-z));
				}
			}
			//oooooooooooooooooooooo
			int pos1=lower_bound(a,a+nn,x)-a;
			if(pos1==nn)
			{
				pos1--;
			}
			for(int j=pos1-1;j<=pos1+1;j++)
			{
				if(j<0||j>=nn)
				{
					continue;
				}
				ll y=a[j];
				int pos3=lower_bound(c,c+kk,y)-c;
				if(pos3==kk)
				{
					pos3--;
				}
				for(int f=pos3-1;f<=pos3+1;f++)
				{
					if(f<0||f>=kk)
					{
						continue;
					}
					ll z=c[f];
					//printf("%lld %lld %lld\n",x,y,z);
					minn=min(minn,(x-y)*(x-y)+(x-z)*(x-z)+(y-z)*(y-z));
				}
			}

		}
		for(int i=0;i<kk;i++)
		{
			ll x=c[i];
			int pos=lower_bound(a,a+nn,x)-a;
			if(pos==nn)
			{
				pos--;
			}
			for(int j=pos-1;j<=pos+1;j++)
			{
				if(j<0||j>=nn)
				{
					continue;
				}
				ll y=a[j];
				int pos2=lower_bound(b,b+mm,y)-b;
				if(pos2==mm)
				{
					pos2--;
				}
				for(int f=pos2-1;f<=pos2+1;f++)
				{
					if(f<0||f>=mm)
					{
						continue;
					}
					ll z=b[f];
					//printf("%lld %lld %lld\n",x,y,z);
					minn=min(minn,(x-y)*(x-y)+(x-z)*(x-z)+(y-z)*(y-z));
				}
			}
			//oooooooooooooooooooooo
			int pos1=lower_bound(b,b+mm,x)-b;
			if(pos1==mm)
			{
				pos1--;
			}
			for(int j=pos1-1;j<=pos1+1;j++)
			{
				if(j<0||j>=mm)
				{
					continue;
				}
				ll y=b[j];
				int pos3=lower_bound(a,a+nn,y)-a;
				if(pos3==nn)
				{
					pos3--;
				}
				for(int f=pos3-1;f<=pos3+1;f++)
				{
					if(f<0||f>=nn)
					{
						continue;
					}
					ll z=a[f];
					//printf("%lld %lld %lld\n",x,y,z);
					minn=min(minn,(x-y)*(x-y)+(x-z)*(x-z)+(y-z)*(y-z));
				}
			}

		}
		printf("%lld\n",minn);
	}
}


#include<cstdio>
#include<cstring>
#include<cmath>
#include<queue>
#include<algorithm>
#include<map>
#include<vector>
#define ll long long
using namespace std;
ll a[100010];
ll b[100010];
ll c[100010];

int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		int n,m,k;
		ll minn=5000000000000000000;
		scanf("%d%d%d",&n,&m,&k);
		map<ll,int> mp1,mp2,mp3;
		int nn=0,mm=0,kk=0;
		for(int i=0;i<n;i++)
		{
			ll x;
			scanf("%lld",&x);
			if(mp1[x]==0)
			{
				mp1[x]=1;
				a[nn++]=x;
			}
		}
		for(int i=0;i<m;i++)
		{
			ll x;
			scanf("%lld",&x);
			if(mp2[x]==0)
			{
				mp2[x]=1;
				b[mm++]=x;
			}
		}
		for(int i=0;i<k;i++)
		{
			ll x;
			scanf("%lld",&x);
			if(mp3[x]==0)
			{
				mp3[x]=1;
				c[kk++]=x;
			}
		}
		sort(a,a+nn);
		sort(b,b+mm);
		sort(c,c+kk);

		for(int i=0;i<nn;i++)
		{
			ll x=a[i];
			int pos=lower_bound(b,b+mm,x)-b;
			if(pos==mm)
			{
				pos--;
			}
			for(int j=pos-1;j<=pos+1;j++)
			{
				if(j<0||j>=mm)
				{
					continue;
				}
				ll y=b[j];
				int pos2=lower_bound(c,c+kk,y)-c;
				if(pos2==kk)
				{
					pos2--;
				}
				for(int f=pos2-1;f<=pos2+1;f++)
				{
					if(f<0||f>=kk)
					{
						continue;
					}
					ll z=c[f];
					//printf("%lld %lld %lld\n",x,y,z);
					minn=min(minn,(x-y)*(x-y)+(x-z)*(x-z)+(y-z)*(y-z));
				}
			}

			//oooooooooooooooooooooo
			int pos1=lower_bound(c,c+kk,x)-c;
			if(pos1==kk)
			{
				pos1--;
			}
			for(int j=pos1-1;j<=pos1+1;j++)
			{
				if(j<0||j>=kk)
				{
					continue;
				}
				ll y=c[j];
				int pos3=lower_bound(b,b+mm,y)-b;
				if(pos3==mm)
				{
					pos3--;
				}
				for(int f=pos3-1;f<=pos3+1;f++)
				{
					if(f<0||f>=mm)
					{
						continue;
					}
					ll z=b[f];
					//printf("%lld %lld %lld\n",x,y,z);
					minn=min(minn,(x-y)*(x-y)+(x-z)*(x-z)+(y-z)*(y-z));
				}
			}
		}
		printf("%lld\n",minn);
	}
}


#include <iostream>
#include <string>
#include <iterator>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <sstream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <iomanip>
#include <functional>
#pragma gcc optimize("o3")
using namespace std;
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long
#define sp system("pause");
#define mod 998244353
#define mxn 2005
#define mxint 1e9+5

ll binary_search(vector<ll>&a, ll value)
{
	if (value < a[0])
		return a[0];
	if (value > a[a.size() - 1])
		return a[a.size() - 1]; //vrati najblizi!!!
	ll lo = 0;
	ll hi = a.size() - 1;

	while (lo <= hi)
	{
		ll mid = lo + ((hi - lo) / 2);

		if (value < a[mid])
			hi = mid - 1;
		else if (value > a[mid])
			lo = mid + 1;
		else
			return a[mid]; //nasao tacan
	}
	//odredi blizi
	return (a[lo] - value) < (value - a[hi]) ? a[lo] : a[hi];
}
ll f(ll x, ll y, ll z)
{
	return 1ll*(x-y)*(x-y) + (x-z)*(x-z) + (z-y)*(z-y);
}
void solve()
{
	ll r, g, b;
	cin >> r >> g >> b;
	vector<ll> red(r), green(g), blue(b);

	for (int i = 0; i < r; i++)
		cin >> red[i];
	for (int i = 0; i < g; i++)
		cin >> green[i];
	for (int i = 0; i < b; i++)
		cin >> blue[i];

	sort(red.begin(), red.end());
	sort(green.begin(), green.end());
	sort(blue.begin(), blue.end());

	ll x, y, z, ans =LLONG_MAX;
	for (int i = 0; i < r; i++)
	{
		x = red[i];
		y = binary_search(green, x);
		z = binary_search(blue, x);
		ans = min(ans, f(x, y, z));
	}
	for (int i = 0; i < g; i++)
	{
		x = green[i];
		y = binary_search(red, x);
		z = binary_search(blue, x);
		ans = min(ans, f(x, y, z));
	}
	for (int i = 0; i < b; i++)
	{
		x = blue[i];
		y = binary_search(green, x);
		z = binary_search(red, x);
		ans = min(ans, f(x, y, z));
	}
	cout << ans << endl;

}

int main()
{
	fast;

	ll t;
	cin >> t;
	while (t--)
	{
		solve();
	}

	return 0;
}


#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<string>
#include<cstring>
#include<climits>
#include<cmath>
#include<map>
#include<set>
#include<deque>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	int T;
	cin >> T;
	const int maxn = 1e5 + 10;
	vector<int>c[3];
	while (T--)
	{
		for (int i = 0; i < 3; i++)
			c[i].clear();
		int num[3];
		cin >> num[0] >> num[1] >> num[2];
		for (int i = 0; i < 3; i++)
		{
			int t;
			for (int j = 0; j < num[i]; j++)
			{
				cin >> t;
				c[i].push_back(t);
			}
			sort(c[i].begin(), c[i].end());
		}
		auto solve = [&](int n)
		{
			auto calc = [&](const long long& a, const long long& b, const long long& c)
			{
				return (a - b) * (a - b) + (b - c) * (b - c) + (a - c) * (a - c);
			};
			auto& master = c[n];
			auto& slave0 = c[(n + 1) % 3];
			auto& slave1 = c[(n + 2) % 3];
			long long ans = INT64_MAX;
			auto get_ans = [&](const vector<int>& a, const vector<int>& b, int i)
			{
				auto snum0 = upper_bound(a.begin(), a.end(), i);
				if (snum0 == a.begin())
					return INT64_MAX;
				snum0--;
				auto snum1 = lower_bound(b.begin(), b.end(), i);
				if (snum1 == b.end())
					return INT64_MAX;
				return calc(i, *snum0, *snum1);
			};
			for (int i : master)
			{
				ans = min(ans, get_ans(slave0, slave1, i));
				ans = min(ans, get_ans(slave1, slave0, i));
			}
			return ans;
		};
		cout << min(solve(0), min(solve(1), solve(2))) << "\n";
	}
}


#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<string>
#include<cstring>
#include<climits>
#include<cmath>
#include<map>
#include<set>
#include<deque>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	int T;
	cin >> T;
	const int maxn = 1e5 + 10;
	vector<int>c[3];
	while (T--)
	{
		for (int i = 0; i < 3; i++)
			c[i].clear();
		int num[3];
		cin >> num[0] >> num[1] >> num[2];
		for (int i = 0; i < 3; i++)
		{
			int t;
			for (int j = 0; j < num[i]; j++)
			{
				cin >> t;
				c[i].push_back(t);
			}
			sort(c[i].begin(), c[i].end());
		}
		auto solve = [&](int n)
		{
			auto calc = [&](const long long& a, const long long& b, const long long& c)
			{
				return (a - b) * (a - b) + (b - c) * (b - c) + (a - c) * (a - c);
			};
			auto& master = c[n];
			auto& slave0 = c[(n + 1) % 3];
			auto& slave1 = c[(n + 2) % 3];
			long long ans = INT64_MAX;
			auto get_ans = [&](const vector<int>& a, const vector<int>& b, int i)
			{
				auto snum0 = upper_bound(a.begin(), a.end(), i);
				if (snum0 == a.begin())
					return INT64_MAX;
				snum0--;
				auto snum1 = lower_bound(b.begin(), b.end(), i);
				if (snum1 == b.end())
					return INT64_MAX;
				return calc(i, *snum0, *snum1);
			};
			for (int i : master)
			{
				ans = min(ans, get_ans(slave0, slave1, i));
				ans = min(ans, get_ans(slave1, slave0, i));
			}
			return ans;
		};
		cout << min(solve(0), min(solve(1), solve(2))) << "\n";
	}
}
b


#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<string>
#include<cstring>
#include<climits>
#include<cmath>
#include<map>
#include<set>
#include<deque>
using namespace std;
const int maxn = 2e5 + 10;
int R, G, B;
long long calc(long long a, long long b, long long c)
{
	return (a - b) * (a - b) + (b - c) * (b - c) + (a - c) * (a - c);
}
struct colour
{
	int cnt = 0;
	int up;
	long long arr[maxn];
	long long now()
	{
		return arr[cnt];
	}
	long long next()
	{
		if (cnt < up)
			return arr[cnt + 1];
		else
			return arr[up];
	}
	void resort()
	{
		sort(arr + 1, arr + up + 1);
		int t = unique(arr + 1, arr + up + 1) - arr - 1;
		up = t;
	}
};
colour r, g, b;
long long ans = INT64_MAX;
void solve(colour& f, colour& s, colour& t)
{
	if (f.now() == s.now() && f.next() < s.next())
		swap(f, s);
	if (s.now() == t.now() && s.next() < t.next())
		swap(s, t);
	if (f.now() == s.now() && f.next() < s.next())
		swap(f, s);
	auto fun1 = [&]()
	{
		ans = min(ans, calc(f.now(), s.next(), t.now()));
		s.cnt++;
		if (s.cnt > s.up)
			return;
		if (s.now() > f.now())
			solve(s, f, t);
		else
			solve(f, s, t);
	};
	auto fun2 = [&]()
	{
		ans = min(ans, calc(f.now(), s.now(), t.next()));
		t.cnt++;
		if (t.cnt > t.up)
			return;
		if (t.now() > f.now())
			solve(t, f, s);
		else
		{
			if (t.now() > s.now())
				solve(f, t, s);
			else
				solve(f, s, t);
		}
	};
	if (calc(f.now(), s.next(), t.now()) < calc(f.now(), s.now(), t.next()))
		fun1();
	else
		fun2();
}

int main()
{
	ios_base::sync_with_stdio(false);
	int T;
	cin >> T;
	while (T--)
	{
		cin >> R >> G >> B;
		for (int i = 1; i <= R; i++)
			cin >> r.arr[i];
		for (int i = 1; i <= G; i++)
			cin >> g.arr[i];
		for (int i = 1; i <= B; i++)
			cin >> b.arr[i];
		r.up = R;
		g.up = G;
		b.up = B;
		r.resort(), g.resort(), b.resort();
		r.cnt = g.cnt = b.cnt = 1;
		ans = calc(r.now(), g.now(), b.now());
		if (r.now() < g.now())
			swap(r, g);
		if (g.now() < b.now())
			swap(g, b);
		if (r.now() < g.now())
			swap(r, g);
		solve(r, g, b);
		cout << ans << "\n";

	}

}


#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<string>
#include<cstring>
#include<climits>
#include<cmath>
#include<map>
#include<set>
#include<deque>
using namespace std;
const int maxn = 2e5 + 10;
int R, G, B;
long long calc(long long a, long long b, long long c)
{
	return (a - b) * (a - b) + (b - c) * (b - c) + (a - c) * (a - c);
}
struct colour
{
	int cnt = 0;
	int up;
	long long arr[maxn];
	long long now()
	{
		return arr[cnt];
	}
	long long next()
	{
		if (cnt < up)
			return arr[cnt + 1];
		else
			return arr[up];
	}
	void resort()
	{
		sort(arr + 1, arr + up + 1);
		int t = unique(arr + 1, arr + up + 1) - arr - 1;
		up = t;
	}
};
colour r, g, b;
long long ans = INT64_MAX;
void solve(colour& f, colour& s, colour& t)
{
	if (f.now() == s.now() && f.next() < s.next())
		swap(f, s);
	if (s.now() == t.now() && s.next() < t.next())
		swap(s, t);
	auto fun1 = [&]()
	{
		ans = min(ans, calc(f.now(), s.next(), t.now()));
		s.cnt++;
		if (s.cnt > s.up)
			return;
		if (s.now() > f.now())
			solve(s, f, t);
		else
			solve(f, s, t);
	};
	auto fun2 = [&]()
	{
		ans = min(ans, calc(f.now(), s.now(), t.next()));
		t.cnt++;
		if (t.cnt > t.up)
			return;
		if (t.now() > f.now())
			solve(t, f, s);
		else
		{
			if (t.now() > s.now())
				solve(f, t, s);
			else
				solve(f, s, t);
		}
	};
	if (calc(f.now(), s.next(), t.now()) < calc(f.now(), s.now(), t.next()))
		fun1();
	else
		fun2();
}

int main()
{
	ios_base::sync_with_stdio(false);
	int T;
	cin >> T;
	while (T--)
	{
		cin >> R >> G >> B;
		for (int i = 1; i <= R; i++)
			cin >> r.arr[i];
		for (int i = 1; i <= G; i++)
			cin >> g.arr[i];
		for (int i = 1; i <= B; i++)
			cin >> b.arr[i];
		r.up = R;
		g.up = G;
		b.up = B;
		r.resort(), g.resort(), b.resort();
		r.cnt = g.cnt = b.cnt = 1;
		ans = calc(r.now(), g.now(), b.now());
		if (r.now() < g.now())
			swap(r, g);
		if (g.now() < b.now())
			swap(g, b);
		if (r.now() < g.now())
			swap(r, g);
		solve(r, g, b);
		cout << ans << "\n";

	}

}