#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <math.h>
#include <string>
#include <stdio.h>
using namespace std;
#define pb push_back
#define mp make_pair

long long n, m, t, k, h, l, r, ans = 1ll << 62;

int bin_search(int x, vector<long long> &a)
{
	int l = 0, r = a.size();
	if (a[l] > x)
		return -1;
	while (r - l > 1)
	{
		int cur = (l + r) / 2;
		if (a[cur] <= x)
			l = cur;
		else
			r = cur;
	}
	return l;
}

void f(vector<long long> & a, vector<long long> &b, vector<long long> &c)
{
	for (int i = 0; i < a.size(); i++)
	{
		int i_b = bin_search(a[i], b);
		int i_c = bin_search(a[i], c);
		vector<long long> opt_b, opt_c;
		if (i_b >= 0)
			opt_b.pb(b[i_b]);
		if (i_c >= 0)
			opt_c.pb(c[i_c]);
		if (i_b < int(b.size()) - 1)
			opt_b.pb(b[i_b + 1]);
		if (i_c < int(c.size()) - 1)
			opt_c.pb(c[i_c + 1]);
		for (int bb = 0; bb < opt_b.size(); bb++)
			for (int cc = 0; cc < opt_c.size(); cc++)
			{
				long long x = a[i], y = opt_b[bb], z = opt_c[cc];
				ans = min(ans, (x - y)*(x - y) + (y - z) * (y - z) + (z - x) * (z - x));
			}
	}
}

int main() {
	//freopen("output.txt", "w", stdout);
	//freopen("input.txt", "r", stdin);

	cin >> t;
	while (t--)
	{
		ans = 1ll << 62;
		cin >> n >> m >> k;
		vector<long long> a(n), b(m), c(k);
		for (int i = 0; i < n; i++)
			cin >> a[i];
		for (int i = 0; i < m; i++)
			cin >> b[i];
		for (int i = 0; i < k; i++)
			cin >> c[i];
		sort(a.begin(), a.end());
		sort(b.begin(), b.end());
		sort(c.begin(), c.end());
		f(a, b, c);
		f(b, a, c);
		f(c, a, b);

		cout << ans << endl;
	}
	return 0;
}


#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <math.h>
#include <string>
#include <stdio.h>
using namespace std;
#define pb push_back
#define mp make_pair

long long n, m, t, k, h, l, r;
vector<vector<int> > e;
long long min_ans = 1, max_ans;
vector <pair<int, int>> dist;
map<int, int> len;
vector<int> pred;
vector<int> sub;
vector<int> ind;
long long ans;
int dfs(int v, int p, int d)
{
	dist[v] = mp(d, v);
	len[v] = d;
	int subb = 0;
	for (int i = 0; i < e[v].size(); i++)
	{
		int to = e[v][i];
		if (to != p)
		{
			pred[to] = v;
			subb += dfs(to, v, d + 1);
		}
	}
	sub[v] = subb + e[v].size();
	return subb;
}
void dfs_2(int v, int p, int cnt)
{
	if (ind[v])
		ans += len[v] - cnt;
	for (int i = 0; i < e[v].size(); i++)
	{
		int to = e[v][i];
		if (ind[v] && to != p)
			dfs_2(to, v, cnt + 1);
		else if(to != p)
			dfs_2(to, v, cnt);
	}
}
int main() {
	//freopen("output.txt", "w", stdout);
	//freopen("input.txt", "r", stdin);

	cin >> n >> k;
	e.resize(n);
	for (int i = 0; i < n - 1; i++)
	{
		int x, y;
		cin >> x >> y;
		e[x - 1].pb(y - 1);
		e[y - 1].pb(x - 1);
	}
	dist.resize(n);
	pred.resize(n);
	sub.resize(n);
	ind.resize(n);
	dfs(0, 0, 0);
	for (int i = 0; i < n; i++)
	{
		dist[i] = mp(dist[i].first - sub[i], dist[i].second);
	}
	sort(dist.begin(), dist.end());
	for (int i = 0; i < k; i++)
	{
		ind[dist[n-1-i].second] = 1;
	}
	dfs_2(0, 0, 0);
	cout << ans;
	return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <memory>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <map>
#include<numeric>
#include<time.h>
#include<cstdlib>
#include <bitset>
#include <set>

typedef long long int LLint;
using namespace std;

int main() {

  int t;
  cin >> t;

  while (t--) {
    vector<int> counts(3);
    cin >> counts[0] >> counts[1] >> counts[2];

    vector<set<int>> Data(3);

    for (int j = 0; j < 3; j++) {
      for (int i = 0; i < counts[j]; i++) {
        int a;
        cin >> a;
        Data[j].insert(a);
      }
    }

    LLint result = LLONG_MAX;

    for (int i = 0; i < 3; i++) {

      int firstAnotherIdx = (i + 1) % 3;
      int secondAnotherIdx = (i + 2) % 3;

      auto firstDyn = Data[firstAnotherIdx].begin();
      auto secondDyn = Data[secondAnotherIdx].begin();

      for (auto it : Data[i]) {
        LLint frstNearestVal = 0;
        if (firstDyn != Data[firstAnotherIdx].end()) {
          auto frstCand = std::lower_bound(firstDyn, Data[firstAnotherIdx].end(), it);
          if (frstCand == Data[firstAnotherIdx].end()) {
            frstCand--;
            frstNearestVal = *frstCand;
            firstDyn = frstCand;
          }
          else {
            frstNearestVal = *frstCand;
            firstDyn = frstCand;
            frstCand--;
            if (frstCand != Data[firstAnotherIdx].end()) {
              frstNearestVal = (abs(frstNearestVal - it) < abs(*frstCand - it)) ? frstNearestVal : *frstCand;
              firstDyn = frstCand;
            }
          }
        } else {
          frstNearestVal = *(--Data[firstAnotherIdx].end());
        }

        LLint secondNearestVal = 0;
        if (secondDyn != Data[secondAnotherIdx].end()) {
          auto secondCand = std::lower_bound(secondDyn, Data[secondAnotherIdx].end(), it);
          if (secondCand == Data[secondAnotherIdx].end()) {
            secondCand--;
            secondNearestVal = *secondCand;
            secondDyn = secondCand;
          }
          else {
            secondNearestVal = *secondCand;
            secondDyn = secondCand;
            secondCand--;
            if (secondCand != Data[secondAnotherIdx].end()) {
              secondNearestVal = (abs(secondNearestVal - it) < abs(*secondCand - it)) ? secondNearestVal : *secondCand;
              secondDyn = secondCand;
            }
          }
        } else {
          frstNearestVal = *(--Data[secondAnotherIdx].end());
        }

        result = min(result, ((LLint)it - frstNearestVal) * ((LLint)it - frstNearestVal) + ((LLint)it - secondNearestVal) * ((LLint)it - secondNearestVal) +
                      (frstNearestVal - secondNearestVal) * (frstNearestVal - secondNearestVal));
      }
    }
    cout << result << endl;
  }

  return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <memory>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <map>
#include<numeric>
#include<time.h>
#include<cstdlib>
#include <bitset>
#include <set>

typedef long long int LLint;
using namespace std;

int main() {

  int t;

  cin >> t;

  while (t--) {
    vector<int> counts(3);
    cin >> counts[0] >> counts[1] >> counts[2];

    vector<set<LLint>> Data(3);

    for (int j = 0; j < 3; j++) {
      for (int i = 0; i < counts[j]; i++) {
        LLint a;
        cin >> a;
        Data[j].insert(a);
      }
    }

    LLint result = LLONG_MAX;

    for (int i = 0; i < 3; i++) {
      for (auto it : Data[i]) {
        int firstAnotherIdx = (i + 1) % 3;
        int secondAnotherIdx = (i + 2) % 3;

        LLint frstNearestVal = 0;
        auto frstCand = std::lower_bound(Data[firstAnotherIdx].begin(), Data[firstAnotherIdx].end(), it);
        if (frstCand == Data[firstAnotherIdx].end()) {
          frstCand--;
          frstNearestVal = *frstCand;
        } else {
          frstNearestVal = *frstCand;
          frstCand--;
          if (frstCand != Data[firstAnotherIdx].end()) {
            frstNearestVal = (abs(frstNearestVal - it) < abs(*frstCand - it)) ? frstNearestVal : *frstCand;
          }
        }

        LLint secondNearestVal = 0;
        auto secondCand = std::lower_bound(Data[secondAnotherIdx].begin(), Data[secondAnotherIdx].end(), it);
        if (secondCand == Data[secondAnotherIdx].end()) {
          secondCand--;
          secondNearestVal = *secondCand;
        }
        else {
          secondNearestVal = *secondCand;
          secondCand--;
          if (secondCand != Data[secondAnotherIdx].end()) {
            secondNearestVal = (abs(secondNearestVal - it) < abs(*secondCand - it)) ? secondNearestVal : *secondCand;
          }
        }

        result = min(result, (it - frstNearestVal) * (it - frstNearestVal) + (it - secondNearestVal) * (it - secondNearestVal) +
                      (frstNearestVal - secondNearestVal) * (frstNearestVal - secondNearestVal));
      }
    }
    cout << result << endl;
  }

  return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <memory>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <map>
#include<numeric>
#include<time.h>
#include<cstdlib>
#include <bitset>
#include <set>

typedef long long int LLint;
using namespace std;

int main() {

  int t;
  cin >> t;

  while (t--) {
    vector<int> counts(3);
    cin >> counts[0] >> counts[1] >> counts[2];

    vector<set<LLint>> Data(3);

    for (int j = 0; j < 3; j++) {
      for (int i = 0; i < counts[j]; i++) {
        LLint a;
        cin >> a;
        Data[j].insert(a);
      }
    }

    LLint result = LLONG_MAX;

    for (int i = 0; i < 3; i++) {

      int firstAnotherIdx = (i + 1) % 3;
      int secondAnotherIdx = (i + 2) % 3;

      auto firstDyn = Data[firstAnotherIdx].begin();
      auto secondDyn = Data[secondAnotherIdx].begin();

      for (auto it : Data[i]) {
        LLint frstNearestVal = 0;
        if (firstDyn != Data[firstAnotherIdx].end()) {
          auto frstCand = std::lower_bound(firstDyn, Data[firstAnotherIdx].end(), it);
          if (frstCand == Data[firstAnotherIdx].end()) {
            frstCand--;
            frstNearestVal = *frstCand;
            firstDyn = frstCand;
          }
          else {
            frstNearestVal = *frstCand;
            firstDyn = frstCand;
            frstCand--;
            if (frstCand != Data[firstAnotherIdx].end()) {
              frstNearestVal = (abs(frstNearestVal - it) < abs(*frstCand - it)) ? frstNearestVal : *frstCand;
              firstDyn = frstCand;
            }
          }
        } else {
          frstNearestVal = *(--Data[firstAnotherIdx].end());
        }

        LLint secondNearestVal = 0;
        if (secondDyn != Data[secondAnotherIdx].end()) {
          auto secondCand = std::lower_bound(secondDyn, Data[secondAnotherIdx].end(), it);
          if (secondCand == Data[secondAnotherIdx].end()) {
            secondCand--;
            secondNearestVal = *secondCand;
            secondDyn = secondCand;
          }
          else {
            secondNearestVal = *secondCand;
            secondDyn = secondCand;
            secondCand--;
            if (secondCand != Data[secondAnotherIdx].end()) {
              secondNearestVal = (abs(secondNearestVal - it) < abs(*secondCand - it)) ? secondNearestVal : *secondCand;
              secondDyn = secondCand;
            }
          }
        } else {
          frstNearestVal = *(--Data[secondAnotherIdx].end());
        }

        result = min(result, (it - frstNearestVal) * (it - frstNearestVal) + (it - secondNearestVal) * (it - secondNearestVal) +
                      (frstNearestVal - secondNearestVal) * (frstNearestVal - secondNearestVal));
      }
    }
    cout << result << endl;
  }

  return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <memory>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <map>
#include<numeric>
#include<time.h>
#include<cstdlib>
#include <bitset>
#include <set>

typedef long long int LLint;
using namespace std;

int main() {

  int t;
  cin >> t;

  while (t--) {
    vector<int> counts(3);
    cin >> counts[0] >> counts[1] >> counts[2];

    vector<set<LLint>> Data(3);

    for (int j = 0; j < 3; j++) {
      for (int i = 0; i < counts[j]; i++) {
        LLint a;
        cin >> a;
        Data[j].insert(a);
      }
    }

    LLint result = LLONG_MAX;

    for (int i = 0; i < 3; i++) {

      int firstAnotherIdx = (i + 1) % 3;
      int secondAnotherIdx = (i + 2) % 3;

      auto firstDyn = Data[firstAnotherIdx].begin();
      auto secondDyn = Data[secondAnotherIdx].begin();

      for (auto it : Data[i]) {
        LLint frstNearestVal = 0;
        auto frstCand = std::lower_bound(firstDyn, Data[firstAnotherIdx].end(), it);
        if (frstCand == Data[firstAnotherIdx].end()) {
          frstCand--;
          frstNearestVal = *frstCand;
        } else {
          frstNearestVal = *frstCand;
          frstCand--;
          if (frstCand != Data[firstAnotherIdx].end()) {
            frstNearestVal = (abs(frstNearestVal - it) < abs(*frstCand - it)) ? frstNearestVal : *frstCand;
          }
        }
        firstDyn = frstCand;

        LLint secondNearestVal = 0;
        auto secondCand = std::lower_bound(secondDyn, Data[secondAnotherIdx].end(), it);
        if (secondCand == Data[secondAnotherIdx].end()) {
          secondCand--;
          secondNearestVal = *secondCand;
        }
        else {
          secondNearestVal = *secondCand;
          secondCand--;
          if (secondCand != Data[secondAnotherIdx].end()) {
            secondNearestVal = (abs(secondNearestVal - it) < abs(*secondCand - it)) ? secondNearestVal : *secondCand;
          }
        }
        secondDyn = secondCand;

        result = min(result, (it - frstNearestVal) * (it - frstNearestVal) + (it - secondNearestVal) * (it - secondNearestVal) +
                      (frstNearestVal - secondNearestVal) * (frstNearestVal - secondNearestVal));
      }
    }
    cout << result << endl;
  }

  return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <memory>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <map>
#include<numeric>
#include<time.h>
#include<cstdlib>
#include <bitset>
#include <set>

typedef long long int LLint;
using namespace std;

int FIND_NEAREST_BITCH_FUCK_COCK_SUCK(const vector<int>& Data, int desiredNumber) {   //returns indx, not value!!!
  int rightIdx = Data.size() - 1;
  int leftIdx = 0;

  if (desiredNumber < Data[leftIdx]) {
    return leftIdx;
  }
  if (desiredNumber > Data.back()) {
    return rightIdx;
  }

  while (abs(leftIdx - rightIdx) > 1) {
    int pivot = (rightIdx + leftIdx) / 2;
    if (desiredNumber > Data[pivot]) {
      leftIdx = pivot;
    } else {
      rightIdx = pivot;
    }
  }
  return (abs(Data[leftIdx]-desiredNumber) < abs(Data[rightIdx] - desiredNumber)) ? leftIdx : rightIdx;
}

int main() {

  int t;
  cin >> t;

  while (t--) {
    vector<int> counts(3);
    cin >> counts[0] >> counts[1] >> counts[2];

    vector<vector<int>> Data(3);

    for (int j = 0; j < 3; j++) {
      unordered_set<int> SHITTYPANTS;
      for (int i = 0; i < counts[j]; i++) {
        int a;
        cin >> a;
        if (SHITTYPANTS.find(a) == SHITTYPANTS.end()) {
          Data[j].push_back(a);
          SHITTYPANTS.insert(a);
        }
      }
    }

    for (int i = 0; i < 3; i++) {
      std::sort(Data[i].begin(), Data[i].end());
    }

    LLint result = LLONG_MAX;

    for (int i = 0; i < 3; i++) {

      int fAIdx = (i + 1) % 3;
      int sAIdx = (i + 2) % 3;

      for (auto it : Data[i]) {
        LLint firstValue = Data[fAIdx][FIND_NEAREST_BITCH_FUCK_COCK_SUCK(Data[fAIdx], it)];
        LLint secondValue = Data[sAIdx][FIND_NEAREST_BITCH_FUCK_COCK_SUCK(Data[sAIdx], it)];

        result = min(result, ((LLint)it - firstValue) * ((LLint)it - firstValue) +
                              ((LLint)it - secondValue) * ((LLint)it - secondValue) +
                              (secondValue - firstValue) * (secondValue - firstValue));
      }
    }

    cout << result << endl;
  }

  return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <memory>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <map>
#include<numeric>
#include<time.h>
#include<cstdlib>
#include <bitset>
#include <set>

typedef long long int LLint;
using namespace std;

int main() {

  int t;
  cin >> t;

  while (t--) {
    vector<int> counts(3);
    cin >> counts[0] >> counts[1] >> counts[2];

    vector<set<LLint>> Data(3);

    for (int j = 0; j < 3; j++) {
      for (int i = 0; i < counts[j]; i++) {
        LLint a;
        cin >> a;
        Data[j].insert(a);
      }
    }

    LLint result = LLONG_MAX;

    for (int i = 0; i < 3; i++) {

      int firstAnotherIdx = (i + 1) % 3;
      int secondAnotherIdx = (i + 2) % 3;

      auto firstDyn = Data[firstAnotherIdx].begin();
      auto secondDyn = Data[secondAnotherIdx].begin();

      for (auto it : Data[i]) {
        LLint frstNearestVal = 0;
        if (firstDyn != Data[firstAnotherIdx].end()) {
          auto frstCand = std::lower_bound(firstDyn, Data[firstAnotherIdx].end(), it);
          if (frstCand == Data[firstAnotherIdx].end()) {
            frstCand--;
            frstNearestVal = *frstCand;
          }
          else {
            frstNearestVal = *frstCand;
            frstCand--;
            if (frstCand != Data[firstAnotherIdx].end()) {
              frstNearestVal = (abs(frstNearestVal - it) < abs(*frstCand - it)) ? frstNearestVal : *frstCand;
            }
          }
          firstDyn = frstCand;
        } else {
          frstNearestVal = *(--Data[firstAnotherIdx].end());
        }

        LLint secondNearestVal = 0;
        if (secondDyn != Data[secondAnotherIdx].end()) {
          auto secondCand = std::lower_bound(secondDyn, Data[secondAnotherIdx].end(), it);
          if (secondCand == Data[secondAnotherIdx].end()) {
            secondCand--;
            secondNearestVal = *secondCand;
          }
          else {
            secondNearestVal = *secondCand;
            secondCand--;
            if (secondCand != Data[secondAnotherIdx].end()) {
              secondNearestVal = (abs(secondNearestVal - it) < abs(*secondCand - it)) ? secondNearestVal : *secondCand;
            }
          }
          secondDyn = secondCand;
        } else {
          frstNearestVal = *(--Data[secondAnotherIdx].end());
        }

        result = min(result, (it - frstNearestVal) * (it - frstNearestVal) + (it - secondNearestVal) * (it - secondNearestVal) +
                      (frstNearestVal - secondNearestVal) * (frstNearestVal - secondNearestVal));
      }
    }
    cout << result << endl;
  }

  return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <memory>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <map>
#include<numeric>
#include<time.h>
#include<cstdlib>
#include <bitset>
#include <set>

typedef long long int LLint;
using namespace std;

int main() {

  int t;
  cin >> t;

  while (t--) {
    vector<int> counts(3);
    cin >> counts[0] >> counts[1] >> counts[2];

    vector<set<LLint>> Data(3);

    for (int j = 0; j < 3; j++) {
      for (int i = 0; i < counts[j]; i++) {
        LLint a;
        cin >> a;
        Data[j].insert(a);
      }
    }

    LLint result = LLONG_MAX;

    for (int i = 0; i < 3; i++) {

      int firstAnotherIdx = (i + 1) % 3;
      int secondAnotherIdx = (i + 2) % 3;

      auto firstDyn = Data[firstAnotherIdx].begin();
      auto secondDyn = Data[secondAnotherIdx].begin();

      for (auto it : Data[i]) {
        LLint frstNearestVal = 0;
        auto frstCand = std::lower_bound(firstDyn, Data[firstAnotherIdx].end(), it);
        if (frstCand == Data[firstAnotherIdx].end()) {
          frstCand--;
          frstNearestVal = *frstCand;
        } else {
          frstNearestVal = *frstCand;
          frstCand--;
          if (frstCand != Data[firstAnotherIdx].end()) {
            frstNearestVal = (abs(frstNearestVal - it) < abs(*frstCand - it)) ? frstNearestVal : *frstCand;
          }
        }
        if(frstCand != Data[firstAnotherIdx].end())
          firstDyn = frstCand;

        LLint secondNearestVal = 0;
        auto secondCand = std::lower_bound(secondDyn, Data[secondAnotherIdx].end(), it);
        if (secondCand == Data[secondAnotherIdx].end()) {
          secondCand--;
          secondNearestVal = *secondCand;
        }
        else {
          secondNearestVal = *secondCand;
          secondCand--;
          if (secondCand != Data[secondAnotherIdx].end()) {
            secondNearestVal = (abs(secondNearestVal - it) < abs(*secondCand - it)) ? secondNearestVal : *secondCand;
          }
        }
        if (secondCand != Data[secondAnotherIdx].end())
          secondDyn = secondCand;

        result = min(result, (it - frstNearestVal) * (it - frstNearestVal) + (it - secondNearestVal) * (it - secondNearestVal) +
                      (frstNearestVal - secondNearestVal) * (frstNearestVal - secondNearestVal));
      }
    }
    cout << result << endl;
  }

  return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <memory>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <map>
#include<numeric>
#include<time.h>
#include<cstdlib>
#include <bitset>
#include <set>

typedef long long int LLint;
using namespace std;

int main() {

  int t;
  cin >> t;

  while (t--) {
    vector<int> counts(3);
    cin >> counts[0] >> counts[1] >> counts[2];

    vector<set<LLint>> Data(3);

    for (int j = 0; j < 3; j++) {
      for (int i = 0; i < counts[j]; i++) {
        LLint a;
        cin >> a;
        Data[j].insert(a);
      }
    }

    LLint result = LLONG_MAX;

    for (int i = 0; i < 3; i++) {
      for (auto it : Data[i]) {
        int firstAnotherIdx = (i + 1) % 3;
        int secondAnotherIdx = (i + 2) % 3;

        LLint frstNearestVal = 0;
        auto frstCand = std::lower_bound(Data[firstAnotherIdx].begin(), Data[firstAnotherIdx].end(), it);
        if (frstCand == Data[firstAnotherIdx].end()) {
          frstCand--;
          frstNearestVal = *frstCand;
        } else {
          frstNearestVal = *frstCand;
          frstCand--;
          if (frstCand != Data[firstAnotherIdx].end()) {
            frstNearestVal = (abs(frstNearestVal - it) < abs(*frstCand - it)) ? frstNearestVal : *frstCand;
          }
        }

        LLint secondNearestVal = 0;
        auto secondCand = std::lower_bound(Data[secondAnotherIdx].begin(), Data[secondAnotherIdx].end(), it);
        if (secondCand == Data[secondAnotherIdx].end()) {
          secondCand--;
          secondNearestVal = *secondCand;
        }
        else {
          secondNearestVal = *secondCand;
          secondCand--;
          if (secondCand != Data[secondAnotherIdx].end()) {
            secondNearestVal = (abs(secondNearestVal - it) < abs(*secondCand - it)) ? secondNearestVal : *secondCand;
          }
        }

        result = min(result, (it - frstNearestVal) * (it - frstNearestVal) + (it - secondNearestVal) * (it - secondNearestVal) +
                      (frstNearestVal - secondNearestVal) * (frstNearestVal - secondNearestVal));
      }
    }
    cout << result << endl;
  }

  return 0;
}


#include <iostream>
#include <vector>
#include <iomanip>
#include <cstring>
#include <string.h>
#include <iterator>
#include <math.h>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <limits.h>
#include <string>
#include <bitset>
#include <map>
#include <numeric>
#include<unordered_map>
#include<unordered_set>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

#define endl cout<<"\n"
#define lli long long int
#define ld long double
#define M_PI (3.14159265358979323846264338327950288)
#define MOD (1000000007)
#define MOD2 (998244353)
#define pii pair<lli,lli>
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define inf 1e17
#define all(a) a.begin(), a.end()
#define rev_all(a) a.rbegin(), a.rend()

using namespace std;
//using namespace __gnu_pbds;

//fast-exponentiation-lli
unsigned lli expo_fast(lli a, lli b) {
	a = a;
	lli result = 1;
	while (b) {
		//multiplyint(tos(result), a);
		if (b & 1)result = (result * a);
		b >>= 1;
		a = (a*a);
	}
	return (result);
}

void take_in(vector<lli> *arr) {
	for (int i = 0; i < arr->size(); i++)cin >> (*(arr))[i];
}

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

}

/* Iterative Function to calculate (x^y)%p in O(log y) */
unsigned lli power(lli x, unsigned lli y, lli p)
{
	lli res = 1;      // Initialize result
	x = x % p;  // Update x if it is more than or equal to p
	while (y > 0) {
		// If y is odd, multiply x with result
		if (y & 1)res = (res*x) % p;
		// y must be even now
		y = y >> 1;
		x = (x*x) % p;
	}
	return res;
}

lli solve(lli x, lli y, lli z) {
	return expo_fast(x - y, 2) + expo_fast(y - z, 2) + expo_fast(x - z, 2);
}

vector<multiset<lli>>v(3, multiset<lli>());
lli ans;

void solve_case(int f, int s, int t) {
	//xyz
	for (auto y : v[s]) {
		auto x = v[f].upper_bound(y); x--;
		if (x == v[f].end())continue;
		auto z = v[t].lower_bound(y);
		if (z == v[t].end())break;
		ans = min(ans, solve(*x, y, *z));
	}
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	lli t; cin >> t;
	while (t--) {
		ans = LLONG_MAX;
		lli nr, ng, nb; cin >> nr >> ng >> nb;
		for (int i = 0; i < nr; i++) {
			lli x; cin >> x; v[0].insert(x);
		}
		for (int i = 0; i < ng; i++) {
			lli x; cin >> x; v[1].insert(x);
		}
		for (int i = 0; i < nb; i++) {
			lli x; cin >> x; v[2].insert(x);
		}
		solve_case(0, 1, 2); solve_case(0, 2, 1);
		solve_case(1, 0, 2); solve_case(1, 2, 0);
		solve_case(2, 0, 1); solve_case(2, 1, 0);
		cout << ans << "\n";
		for (int j = 0; j < 3; j++) {
			while (!v[j].empty())v[j].erase(v[j].begin());
		}
	}
	//system("PAUSE");
}


#include <cstdio>
#include <algorithm>
#define ll long long
using namespace std;
inline void in(int &x){
	char c=getchar();
	while (c<'0'||c>'9')  c=getchar();
	for (x=0;c>='0'&&c<='9';c=getchar())  x=x*10+c-'0';
}
ll t,n1,n2,n3,a[100005],b[100005],c[100005],ans;
inline bool cmp(int a,int b){
	return a<b;
}
inline ll work(ll a,ll b,ll c){
	return (a-b)*(a-b)+(a-c)*(a-c)+(b-c)*(b-c);
}
inline ll min(ll a,ll b){
	return a<b?a:b;
}
const ll INF=1999999996000000015ll;
int main(){
	scanf("%lld",&t);
//	printf("%lld\n",INF);
	while (t--){ans=INF;
		scanf("%lld%lld%lld",&n1,&n2,&n3);
		for (int i=1;i<=n1;i++)  scanf("%lld",&a[i]);
		for (int i=1;i<=n2;i++)  scanf("%lld",&b[i]);
		for (int i=1;i<=n3;i++)  scanf("%lld",&c[i]);
//		printf("!\n");
		sort(a+1,a+n1+1,cmp);
		sort(b+1,b+n2+1,cmp);
		sort(c+1,c+n3+1,cmp);
		ll aaa=1,bbb=1,ccc=1;
//		printf("!\n");
		for (int i=4;i<=n1+n2+n3;i++){
			ans=min(ans,work(a[aaa],b[bbb],c[ccc]));
//			printf("%lld %lld %lld\n",aaa,bbb,ccc);
			if (aaa==n1&&bbb==n2&&ccc==n3)  continue;
			if (aaa==n1){
				if (bbb==n2) ccc++;
				else  if (ccc==n3)  bbb++;
				else  if (b[bbb]<=c[ccc])  bbb++;
				else  ccc++;
			}
			else  if (bbb==n2){
				if (aaa==n1) ccc++;
				else  if (ccc==n3)  aaa++;
				else  if (a[aaa]<=c[ccc])  aaa++;
				else  ccc++;
			}
			else  if (ccc==n3){
				if (bbb==n2) aaa++;
				else  if (aaa==n1)  bbb++;
				else  if (b[bbb]<=a[aaa])  bbb++;
				else  aaa++;
			}
			else{
				if (a[aaa]<=b[bbb]){
					if (a[aaa]<=c[ccc])  aaa++;
					else  ccc++;
				}
				else{
					if (b[bbb]<=c[ccc])  bbb++;
					else  ccc++;
				}
			}
		}
		printf("%lld\n",ans);
	}
	return 0;
}


#include <cstdio>
#include <algorithm>
#define ll long long
using namespace std;
inline void in(int &x){
	char c=getchar();
	while (c<'0'||c>'9')  c=getchar();
	for (x=0;c>='0'&&c<='9';c=getchar())  x=x*10+c-'0';
}
ll t,n1,n2,n3,a[100005],b[100005],c[100005],ans;
inline bool cmp(int a,int b){
	return a<b;
}
inline ll work(ll a,ll b,ll c){
	return (a-b)*(a-b)+(a-c)*(a-c)+(b-c)*(b-c);
}
inline ll min(ll a,ll b){
	return a<b?a:b;
}
const ll INF=1999999996000000015ll;
int main(){
	scanf("%lld",&t);
//	printf("%lld\n",INF);
	while (t--){ans=INF;
		scanf("%lld%lld%lld",&n1,&n2,&n3);
		for (int i=1;i<=n1;i++)  scanf("%lld",&a[i]);
		for (int i=1;i<=n2;i++)  scanf("%lld",&b[i]);
		for (int i=1;i<=n3;i++)  scanf("%lld",&c[i]);
//		printf("!\n");
		sort(a+1,a+n1+1,cmp);
		sort(b+1,b+n2+1,cmp);
		sort(c+1,c+n3+1,cmp);
		ll aaa=1,bbb=1,ccc=1;
//		printf("!\n");
		for (int i=3;i<=n1+n2+n3;i++){
			ans=min(ans,work(a[aaa],b[bbb],c[ccc]));
//			printf("%lld %lld %lld\n",aaa,bbb,ccc);
			if (aaa==n1&&bbb==n2&&ccc==n3)  continue;
			if (aaa==n1){
				if (bbb==n2) ccc++;
				else  if (ccc==n3)  bbb++;
				else  if (b[bbb]<=c[ccc])  bbb++;
				else  ccc++;
			}
			else  if (bbb==n2){
				if (aaa==n1) ccc++;
				else  if (ccc==n3)  aaa++;
				else  if (a[aaa]<=c[ccc])  aaa++;
				else  ccc++;
			}
			else  if (ccc==n3){
				if (bbb==n2) aaa++;
				else  if (aaa==n1)  bbb++;
				else  if (b[bbb]<=a[aaa])  bbb++;
				else  aaa++;
			}
			else{
				if (a[aaa]<=b[bbb]){
					if (a[aaa]<=c[ccc])  aaa++;
					else  ccc++;
				}
				else{
					if (b[bbb]<=c[ccc])  bbb++;
					else  ccc++;
				}
			}
		}
		printf("%lld\n",ans);
	}
	return 0;
}


#include <cstdio>
#include <algorithm>
#define ll long long
using namespace std;
inline void in(int &x){
	char c=getchar();
	while (c<'0'||c>'9')  c=getchar();
	for (x=0;c>='0'&&c<='9';c=getchar())  x=x*10+c-'0';
}
ll t,n1,n2,n3,a[100005],b[100005],c[100005],ans;
inline bool cmp(int a,int b){
	return a<b;
}
inline ll work(ll a,ll b,ll c){
	return (a-b)*(a-b)+(a-c)*(a-c)+(b-c)*(b-c);
}
inline ll min(ll a,ll b){
	return a<b?a:b;
}
const ll INF=1999999996000000015ll;
int main(){
	scanf("%lld",&t);
//	printf("%lld\n",INF);
	while (t--){ans=INF;
		scanf("%lld%lld%lld",&n1,&n2,&n3);
		for (int i=1;i<=n1;i++)  scanf("%lld",&a[i]);
		for (int i=1;i<=n2;i++)  scanf("%lld",&b[i]);
		for (int i=1;i<=n3;i++)  scanf("%lld",&c[i]);
//		printf("!\n");
		sort(a+1,a+n1+1,cmp);
		sort(b+1,b+n2+1,cmp);
		sort(c+1,c+n3+1,cmp);
		ll aaa=1,bbb=1,ccc=1;
//		printf("!\n");
		for (int i=3;i<=n1+n2+n3;i++){
			ans=min(ans,work(a[aaa],b[bbb],c[ccc]));
//			printf("%lld %lld %lld\n",aaa,bbb,ccc);
			if (aaa==n1&&bbb==n2&&ccc==n3)  continue;
			if (aaa==n1){
				if (bbb==n2) ccc++;
				else  if (ccc==n3)  bbb++;
				else  if (b[bbb]<c[ccc])  bbb++;
				else  if (b[bbb]>c[ccc])  ccc++;
				else  if (c[ccc+1]<=b[bbb+1])  ccc++;
				else  bbb++;
			}
			else  if (bbb==n2){
				if (aaa==n1) ccc++;
				else  if (ccc==n3)  aaa++;
				else  if (a[aaa]<c[ccc])  aaa++;
				else  if (a[aaa]>c[ccc])  ccc++;
				else  if (c[ccc+1]<=a[aaa+1])  ccc++;
				else  aaa++;
			}
			else  if (ccc==n3){
				if (bbb==n2) aaa++;
				else  if (aaa==n1)  bbb++;
				else  if (b[bbb]<a[aaa])  bbb++;
				else  if (b[bbb]>a[aaa])  aaa++;
				else  if (a[aaa+1]<=b[bbb+1])  aaa++;
				else  bbb++;
			}
			else{
				if (a[aaa]<=b[bbb]){
					if (a[aaa]<c[ccc])  aaa++;
					else  if (a[aaa]>c[ccc])  ccc++;
					else  if (a[aaa+1]<=c[ccc+1])  aaa++;
					else  ccc++;
				}
				else{
					if (b[bbb]<c[ccc])  bbb++;
					else  if (b[bbb]>c[ccc])  ccc++;
					else  if (b[bbb+1]<=c[ccc+1])  bbb++;
					else  ccc++;
				}
			}
		}
		printf("%lld\n",ans);
	}
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
//#include <stdafx.h>
//#include <tchar.h>
//#include "targetver.h"
#include <intrin.h>
//
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

//#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
//#endif>

#define LL long long
#define MOD 1000000007
#define INF 1000000000
#define LINF 9000000000000000000

using namespace std;

const int N = 2e5 + 10;
LL a[3][N];

LL calc(LL x, LL y, LL z) {

	return (x - y)*(x - y) + (x - z)*(x - z) + (y - z)*(y - z);

}

int main()
{

	LL t,r,g,b;
	scanf("%lld", &t);

	while (t--) {

		LL ans = LINF;

		scanf("%lld%lld%lld", &r, &g, &b);

		for (int i = 1;i <= r;i++)
			scanf("%lld", &a[0][i]);

		for (int i = 1;i <= g;i++)
			scanf("%lld", &a[1][i]);

		for (int i = 1;i <= b;i++)
			scanf("%lld", &a[2][i]);

		sort(a[0] + 1, a[0] + r + 1);
		sort(a[1] + 1, a[1] + g + 1);
		sort(a[2] + 1, a[2] + b + 1);

		for (int i = 1;i <= r;i++) {

			LL ind1 = upper_bound(a[1] + 1, a[1] + g + 1, a[0][i]) - a[1];
			LL ind2 = lower_bound(a[2] + 1, a[2] + 1 + b, a[0][i]) - a[2];

			if (ind2 == b + 1)
				ind2--;

			ind1 = max(1ll, ind1 - 1);
			ans = min(ans, calc(a[0][i], a[1][ind1], a[2][ind2]));

			ind1 = lower_bound(a[1] + 1, a[1] + 1 + g, a[0][i]) - a[1];
			ind2 = upper_bound(a[2] + 1, a[2] + b + 1, a[0][i]) - a[2];

			if (ind1 == g + 1)
				ind1--;

			ind2 = max(1ll, ind2 - 1);

			ans = min(ans, calc(a[0][i], a[1][ind1], a[2][ind2]));
		}

		for (int i = 1;i <= g;i++) {

			LL ind1 = upper_bound(a[0] + 1, a[0] + r + 1, a[1][i]) - a[0];
			LL ind2 = lower_bound(a[2] + 1, a[2] + 1 + b, a[1][i]) - a[2];

			if (ind2 == b + 1)
				ind2--;

			ind1 = max(1ll, ind1 - 1);
			ans = min(ans, calc(a[1][i], a[0][ind1], a[2][ind2]));

			ind1 = lower_bound(a[0] + 1, a[0] + 1 + r, a[1][i]) - a[0];
			ind2 = upper_bound(a[2] + 1, a[2] + b + 1, a[1][i]) - a[2];

			if (ind1 == r + 1)
				ind1--;

			ind2 = max(1ll, ind2 - 1);

			ans = min(ans, calc(a[1][i], a[0][ind1], a[2][ind2]));
		}

		for (int i = 1;i <= b;i++) {

			LL ind1 = upper_bound(a[1] + 1, a[1] + g + 1, a[2][i]) - a[1];
			LL ind2 = lower_bound(a[0] + 1, a[0] + 1 + r, a[2][i]) - a[0];

			if (ind2 == r + 1)
				ind2--;

			ind1 = max(1ll, ind1 - 1);
			ans = min(ans, calc(a[2][i], a[1][ind1], a[0][ind2]));

			ind1 = lower_bound(a[1] + 1, a[1] + 1 + g, a[2][i]) - a[1];
			ind2 = upper_bound(a[0] + 1, a[0] + r + 1, a[2][i]) - a[0];

			if (ind1 == g + 1)
				ind1--;

			ind2 = max(1ll, ind2 - 1);

			ans = min(ans, calc(a[2][i], a[1][ind1], a[0][ind2]));
		}
		printf("%lld\n", ans);
	}
	//cin >> t;
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int T;
int n[5];
int t[5] = { 0,1,2 };
long long a[5][100002];
long long hashv(long long x, long long y, long long z)
{
	return (x - y) * (x - y) + (y - z) * (y - z) + (z - x) * (z - x);
}
int main()
{
	cin >> T;
	while (T--)
	{
		long long ans;
		cin >> n[0] >> n[1] >> n[2];
		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]);
		}
		ans = hashv(a[0][0], a[1][0], a[2][0]);
		do
		{
			int i1 = 0, i2 = 0;
			for (int i = 0; i < n[t[0]]; i++)
			{
				while (i1 + 1 < n[t[1]] && a[t[1]][i1 + 1] < a[t[0]][i])
					i1++;
				while (i2 + 1 < n[t[2]] && a[t[2]][i2 + 1] < a[t[0]][i])
					i2++;
				if (i2 != n[t[2]] && i1 != n[t[1]])
					ans = min(ans, hashv(a[t[0]][i], a[t[1]][i1], a[t[2]][i2]));
			}
		} while (next_permutation(t, t + 3));
		cout << ans << '\n';
	}
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int t;
int r, g, b;
long long x;
vector<pair<long long, int>> a;
int main()
{
	cin >> t;
	while (t--)
	{
		a.clear();
		cin >> r >> g >> b;
		for (int i = 0; i < r; i++)
		{
			cin >> x;
			a.push_back(make_pair(x, 1));
		}
		for (int i = 0; i < g; i++)
		{
			cin >> x;
			a.push_back(make_pair(x, 2));
		}
		for (int i = 0; i < b; i++)
		{
			cin >> x;
			a.push_back(make_pair(x, 3));
		}
		sort(a.begin(), a.end());
		r = -1;
		g = -1;
		b = -1;
		int pr = -1, pg = -1, pb = -1;
		int i = 0;
		long long cur = 0;
		long long mi = -1;
		while (i<a.size())
		{
			if (a[i].second == 1)
			{
				pr = r;
				r = i;
			}
			if (a[i].second == 2)
			{
				pg = g;	g = i;
			}
			if (a[i].second == 3)
			{
				pb = b;	b = i;
			}
			if (r != -1 && g != -1 && b != -1)
			{
				cur = (a[r].first - a[g].first) * (a[r].first - a[g].first) +
					(a[r].first - a[b].first) * (a[r].first - a[b].first) +
					(a[b].first - a[g].first) * (a[b].first - a[g].first);
				if (mi == -1 || cur < mi)
					mi = cur;
			}
			if (pr != -1 && g != -1 && b != -1)
			{
				cur = (a[pr].first - a[g].first) * (a[pr].first - a[g].first) +
					(a[pr].first - a[b].first) * (a[pr].first - a[b].first) +
					(a[b].first - a[g].first) * (a[b].first - a[g].first);
				if (mi == -1 || cur < mi)
					mi = cur;
			}
			if (r != -1 && pg != -1 && b != -1)
			{
				cur = (a[r].first - a[pg].first) * (a[r].first - a[pg].first) +
					(a[r].first - a[b].first) * (a[r].first - a[b].first) +
					(a[b].first - a[pg].first) * (a[b].first - a[pg].first);
				if (mi == -1 || cur < mi)
					mi = cur;
			}
			if (r != -1 && g != -1 && pb != -1)
			{
				cur = (a[r].first - a[g].first) * (a[r].first - a[g].first) +
					(a[r].first - a[pb].first) * (a[r].first - a[pb].first) +
					(a[pb].first - a[g].first) * (a[pb].first - a[g].first);
				if (mi == -1 || cur < mi)
					mi = cur;
			}
			if (pr != -1 && pg != -1 && b != -1)
			{
				cur = (a[pr].first - a[pg].first) * (a[pr].first - a[pg].first) +
					(a[pr].first - a[b].first) * (a[pr].first - a[b].first) +
					(a[b].first - a[pg].first) * (a[b].first - a[pg].first);
				if (mi == -1 || cur < mi)
					mi = cur;
			}
			if (r != -1 && pg != -1 && pb != -1)
			{
				cur = (a[r].first - a[pg].first) * (a[r].first - a[pg].first) +
					(a[r].first - a[pb].first) * (a[r].first - a[pb].first) +
					(a[pb].first - a[pg].first) * (a[pb].first - a[pg].first);
				if (mi == -1 || cur < mi)
					mi = cur;
			}
			if (pr != -1 && g != -1 && pb != -1)
			{
				cur = (a[pr].first - a[g].first) * (a[pr].first - a[g].first) +
					(a[pr].first - a[pb].first) * (a[pr].first - a[pb].first) +
					(a[pb].first - a[g].first) * (a[pb].first - a[g].first);
				if (mi == -1 || cur < mi)
					mi = cur;
			}
			i++;
		}
		cout << mi << '\n';
	}
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int T;
int n[5];
int t[5] = { 0,1,2 };
long long a[5][100002];
long long hashv(long long x, long long y, long long z)
{
	return (x - y) * (x - y) + (y - z) * (y - z) + (z - x) * (z - x);
}
int main()
{
	cin >> T;
	while (T--)
	{
		long long ans;
		cin >> n[0] >> n[1] >> n[2];
		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]);
		}
		ans = hashv(a[0][0], a[1][0], a[2][0]);
		do
		{
			int i1 = -1, i2 = 0;
			for (int i = 0; i < n[t[0]]; i++)
			{
				while (i1 + 1 < n[t[1]] && a[t[1]][i1 + 1] <= a[t[0]][i])
					i1++;
				while (i2 < n[t[2]] && a[t[2]][i2] < a[t[0]][i])
					i2++;
				if (i1 != -1 && i2 != n[t[2]])
					ans = min(ans, hashv(a[t[0]][i], a[t[1]][i1], a[t[2]][i2]));
			}
		} while (next_permutation(t, t + 3));
		cout << ans << '\n';
	}
	return 0;
}


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

using namespace std;

int main() {
	//ifstream cin("C:\\Users\\17865\\Desktop\\P1.txt");

	int t;
	cin >> t;
	for (int i = 0; i < t; ++i) {
		//����, Ȼ�󻬶����ڴ���, le mid right(���Զ��mid)
		long long nr, ng, nb;
		cin >> nr >> ng >> nb;
		vector<pair<long long, long long>> total;	//ֵ, ���
		total.reserve(nr + ng + nb);

		for (int num = 0; num < nr; ++num) {
			long long temp;
			cin >> temp;
			total.push_back({ temp, 1LL });
		}
		for (int num = 0; num < ng; ++num) {
			long long temp;
			cin >> temp;
			total.push_back({ temp, 2LL });
		}
		for (int num = 0; num < nb; ++num) {
			long long temp;
			cin >> temp;
			total.push_back({ temp, 3LL });
		}

		//Ԥ����: ����, ��ֵ, �������
		sort(total.begin(), total.end(), [](pair<long long, long long>& p1, pair<long long, long long>& p2) {
			if (p1.first < p2.first) return true;
			else if (p1.first > p2.first) return false;
			else return p1.second < p2.second;
		});

		//����������
		long long leIndex = 0;					//����ʼֵ, ʹ����ʽѭ����һ�����ж�
		long long leType = total[0].second;
		vector<long long> midIndexes;
		long long midType = -1;

		long long ret = LLONG_MAX;

		//��ʼ��
		for (int preIndex = 1; preIndex < (nr + ng + nb); ++preIndex) {
			long long preType = total[preIndex].second;
			if (preType == leType) {		//����߽���ͬ���
				if (midType == -1)	//�м�ֵΪ��, ������߽�(��ǰֻ��¼�˵�һ��߽�Ԫ��)
				{
					leIndex = preIndex;
				}
				else {		//�м���Ԫ��, ��ǰ��߽���м�ֵ����Ӧ������, ��ǰ��߽�=�м�ֵ������±�, ��ǰ�ұ߽�=��ǰ�±�
					swap(leType, midType);
					leIndex = midIndexes.back();
					midIndexes = { preIndex };
				}
			}
			else if (midType == -1) {	//��ǰ�м�ֵ�ǿյ�, �����м�ֵ
				midType = preType;
				midIndexes = { preIndex };
			}
			else if (preType == midType) {	//�����м�ֵ���, ����
				midIndexes.push_back(preIndex);		//Ҳ������Ż�, ����ֻ��Ҫ�м�ֵ�����±�ֻ������С�ĺ�����?
			}
			else {	//�ұ߽������, ���Խ��м���
				long long leftVal = total[leIndex].first;
				long long rightVal = total[preIndex].first;
				for (auto& midIndex : midIndexes) {
					long long midVal = total[midIndex].first;
					ret = min(ret, (leftVal - midVal) * (leftVal - midVal) +
						(leftVal - rightVal) * (leftVal - rightVal) +
						(midVal - rightVal) * (midVal - rightVal)
					);
				}
				//����:��߽�=�м�ֵ����, ������=�м�����; �м�ֵ=��ǰ�±�, �м�����=��ǰ����
				leIndex = midIndexes.back();
				leType = midType;
				midIndexes = {preIndex};
				midType = preType;
			}
		}
		cout << ret << endl;
	}
	return 0;
}


#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#define ll long long
using namespace std;
const int N=3e5+1000;
ll max1[N],max2[N],max3[N];
ll min1[N],min2[N],min3[N];
int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		ll a,b,c;
		vector<pair<ll,ll> >v;
		scanf("%lld%lld%lld",&a,&b,&c);
		for(ll i=1;i<=a;i++)
		{
			ll x;
			scanf("%lld",&x);
			v.push_back(make_pair(x,1));
		}
		for(ll i=1;i<=b;i++)
		{
			ll x;
			scanf("%lld",&x);
			v.push_back(make_pair(x,2));
		}
		for(ll i=1;i<=c;i++)
		{
			ll x;
			scanf("%lld",&x);
			v.push_back(make_pair(x,3));
		}
		sort(v.begin() ,v.end() );
		ll minn=3e18;
		for(int i=0;i<v.size()+10;i++)
		{
			min1[i]=min2[i]=min3[i]=max1[i]=max2[i]=max3[i]=-1;
		}
		for(int i=v.size()-1;i>=0;i--)
		{
			ll x=v[i].first;
			ll y=v[i].second;
			if(y==1)
			{
				min1[i]=x;
				min2[i]=min2[i+1];
				min3[i]=min3[i+1];
			}
			else if(y==2)
			{
				min2[i]=x;
				min1[i]=min1[i+1];
				min3[i]=min3[i+1];
			}
			else
			{
				min3[i]=x;
				min1[i]=min1[i+1];
				min2[i]=min2[i+1];
			}
		}
			for(int i=0;i<v.size() ;i++)
		{
			ll x=v[i].first;
			ll y=v[i].second;
			if(y==1)
			{
				max1[i]=x;
				if(i==0)
				{
					max2[i]=-1;
				    max3[i]=-1;
				}
				else
				{
					max2[i]=max2[i-1];
					max3[i]=max3[i-1];
				}

			}
			if(y==2)
			{
				max2[i]=x;
				if(i==0)
				{
					max1[i]=-1;
				    max3[i]=-1;
				}
				else
				{
					max1[i]=max1[i-1];
					max3[i]=max3[i-1];
				}

			}
			if(y==3)
			{
				max3[i]=x;
				if(i==0)
				{
					max1[i]=-1;
				    max2[i]=-1;
				}
				else
				{
					max1[i]=max1[i-1];
					max2[i]=max2[i-1];
				}

			}
		}

		for(int i=0;i<v.size();i++)
		{
			ll x=v[i].first;
			ll y=v[i].second;
			if(y==1)
			{
				if(max2[i]!=-1&&max3[i]!=-1)
				{
					minn=min(minn,((x-max2[i])*(x-max2[i])+(x-max3[i])*(x-max3[i])+(max3[i]-max2[i])*(max3[i]-max2[i])));
				}
			    if(max2[i]!=-1&&min3[i]!=-1)
				{
					minn=min(minn,((x-max2[i])*(x-max2[i])+(x-min3[i])*(x-min3[i])+(min3[i]-max2[i])*(min3[i]-max2[i])));
				}
				if(max3[i]!=-1&&min2[i]!=-1)
				{
					minn=min(minn,((x-max3[i])*(x-max3[i])+(x-min2[i])*(x-min2[i])+(min2[i]-max3[i])*(min2[i]-max3[i])));
				}
				if(min2[i]!=-1&&min3[i]!=-1)
				{
					minn=min(minn,((x-min2[i])*(x-min2[i])+(x-min3[i])*(x-min3[i])+(min3[i]-min2[i])*(min3[i]-min2[i])));
				}
			}
			else if(y==2)
			{
				if(max1[i]!=-1&&max3[i]!=-1)
				{
					minn=min(minn,((x-max1[i])*(x-max1[i])+(x-max3[i])*(x-max3[i])+(max3[i]-max1[i])*(max3[i]-max1[i])));
				}
			    if(max1[i]!=-1&&min3[i]!=-1)
				{
					minn=min(minn,((x-max1[i])*(x-max1[i])+(x-min3[i])*(x-min3[i])+(min3[i]-max1[i])*(min3[i]-max1[i])));
				}
				if(max3[i]!=-1&&min1[i]!=-1)
				{
					minn=min(minn,((x-max3[i])*(x-max3[i])+(x-min1[i])*(x-min1[i])+(min1[i]-max3[i])*(min1[i]-max3[i])));
				}
				if(min1[i]!=-1&&min3[i]!=-1)
				{
					minn=min(minn,((x-min1[i])*(x-min1[i])+(x-min3[i])*(x-min3[i])+(min3[i]-min1[i])*(min3[i]-min1[i])));
				}
			}
			else
			{
				if(max2[i]!=-1&&max1[i]!=-1)
				{
					minn=min(minn,((x-max2[i])*(x-max2[i])+(x-max1[i])*(x-max1[i])+(max1[i]-max2[i])*(max1[i]-max2[i])));
				}
			    if(max2[i]!=-1&&min1[i]!=-1)
				{
					minn=min(minn,((x-max2[i])*(x-max2[i])+(x-min1[i])*(x-min1[i])+(min1[i]-max2[i])*(min1[i]-max2[i])));
				}
				if(max1[i]!=-1&&min2[i]!=-1)
				{
					minn=min(minn,((x-max1[i])*(x-max1[i])+(x-min2[i])*(x-min2[i])+(min2[i]-max1[i])*(min2[i]-max1[i])));
				}
				if(min2[i]!=-1&&min1[i]!=-1)
				{
					minn=min(minn,((x-min2[i])*(x-min2[i])+(x-min1[i])*(x-min1[i])+(min1[i]-min2[i])*(min1[i]-min2[i])));
				}
			}
		}
		printf("%lld\n",minn);
	}
}


#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <algorithm>
#include <fstream>
using namespace std;
long long sqr(int  a) { return 1LL * a * a; }

long long solve(vector<int>& a, vector<int>& b, vector<int>& c) {
	long long res = 2e18;
	for (int i = 0; i < b.size(); i++) {
		auto it1 = upper_bound(a.begin(), a.end(), b[i]);
		if (it1 != a.begin())
			it1--;
		auto it2 = lower_bound(c.begin(), c.end(), b[i]);
		if (it2 == c.end())
			it2--;
		long long v[] = { *it1, b[i], *it2};
		long long curr = 0;
		for (int k = 0; k < 3; k++) {
			curr += sqr(v[k] - (v[(k + 1) % 3]));
		}
		res = min(res, curr);
	}
	return res;
}

int main()
{
#ifndef ONLINE_JUDGE
	ifstream cin("input.txt");
	ofstream cout("output.txt");
#endif

	int t;
	cin >> t;
	while (t--) {
		int n1, n2, n3;
		cin >> n1 >> n2 >> n3;
		vector<int> a(n1);
		vector<int> b(n2);
		vector<int> c(n3);
		for (int i = 0; i < n1; i++) {
			cin >> a[i];
		}
		for (int i = 0; i < n2; i++) {
			cin >> b[i];
		}
		for (int i = 0; i < n3; i++) {
			cin >> c[i];
		}

		sort(a.begin(), a.end());
		sort(b.begin(), b.end());
		sort(c.begin(), c.end());

		long long res = 2e18;
		res = min(res, solve(a, b, c));
		res = min(res, solve(a, c, b));
		res = min(res, solve(b, a, c));
		res = min(res, solve(b, c, a));
		res = min(res, solve(c, a, b));
		res = min(res, solve(c, b, a));

		cout << res << '\n';
	}

	return 0;
}


#include<iostream>
#include<string.h>
#include<set>
#include<algorithm>
using namespace std;
#define ll long long
#define N 200005
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f

#define pb push_back
#define lb lower_bound
#define mem(a,b) memset(a,b,sizeof(a))

#define intq() int Qq;cin>>Qq;while(Qq--)
#define fo(i,n) for(int i=0;i<n;i++)
#define foo(i,n) for(int i=1;i<=n;i++)

#define pr(x) cout<<x<<" "
#define prk() cout<<" "
#define prln() cout<<"\n"
#define sc(a) scanf("%lld",&a)
set<ll>x,y,z,t;
int main()
{
	intq(){
		x.clear();y.clear();z.clear();t.clear();
		ll a,b,c;cin>>a>>b>>c;
		ll o;
		ll ans=INF;
		while(a--){
			cin>>o;x.insert(o);t.insert(o);
		}
		while(b--){
			cin>>o;y.insert(o);t.insert(o);
		}
		while(c--){
			cin>>o;z.insert(o);t.insert(o);
		}
		set<ll>::iterator it;
		ll xx=*x.begin(),yy=*y.begin(),zz=*z.begin();
		for(it=t.begin();it!=t.end();it++){
			ll temp=*it;
			if(x.lb(temp)!=x.end()){
				if(*x.lb(temp)-*it<*it-xx)
				xx=*x.lb(temp);
			}
			if(y.lb(temp)!=y.end()){
				if(*y.lb(temp)-*it<*it-yy)yy=*y.lb(temp);
			}
			if(z.lb(temp)!=z.end()){
				if(*z.lb(temp)-*it<*it-zz)zz=*z.lb(temp);
			}
			ll t1=xx-yy,t2=xx-zz,t3=yy-zz;
			ans=min(ans,t1*t1+t2*t2+t3*t3);
		}
		cout<<ans<<"\n";
	}
	return 0;
}


#include <stdio.h>
#include <iostream>
#include <bitset>
#include <map>
#include <stack>
#include <algorithm>
#include <math.h>
#include <queue>
#include <vector>
#include <string.h>
#define mem(x,b) memset(x,b,sizeof(x))
#define mp(a,b) make_pair(a,b)
#define debug(a) cout<<a<<endl
#define maxn 100005
using namespace std;
typedef long long ll;
typedef double db;
const int mod=1e9+7;
ll ans;
ll f(int x,int y,int z){
	ll res=(ll)(x-y)*(ll)(x-y)+(ll)(x-z)*(ll)(x-z)+(ll)(z-y)*(ll)(z-y);
	return res;
}
void slove(int* r,int* g,int* b,int nr,int ng,int nb){
	for(int i=0;i<nr;i++){
    		int l=0,r1=ng-1,mid,u,t,as=-1;
    		while(r1-l>=0){
    			mid=(r1+l)>>1;
    			if(g[mid]>r[i]){
    				r1=mid-1;
    			}else{
    				as=mid;
    				l=mid+1;
    			}
    		}
    		if(as==-1)continue;
    		u=as;
    		l=0,r1=nb-1,as=-1;
    		while(r1-l>=0){
    			mid=(r1+l)>>1;
    			if(b[mid]<r[i]){
    				l=mid+1;
    			}else{
    				as=mid;
    				r1=mid-1;
    			}
    		}
    		if(as==-1)continue;
    		t=as;
    		ans=min(ans,f(g[u],r[i],b[t]));
    }
}
int main()
{
    int t;
    scanf("%d",&t);
    while(t--){
    	int r[maxn],g[maxn],b[maxn];
    	int nr,ng,nb;
    	ans=2e18;
    	scanf("%d%d%d",&nr,&ng,&nb);
    	for(int i=0;i<nr;i++){
    		scanf("%d",&r[i]);
    	}
    	for(int i=0;i<ng;i++){
    		scanf("%d",&g[i]);
    	}
    	for(int i=0;i<nb;i++){
    		scanf("%d",&b[i]);
    	}
    	sort(r,r+nr);
    	sort(g,g+ng);
    	sort(b,b+nb);
    	slove(r,g,b,nr,ng,nb);
    	slove(r,b,g,nr,nb,ng);
    	slove(g,r,b,ng,nr,nb);
    	slove(g,b,r,ng,nb,nr);
    	slove(b,g,r,nb,ng,nr);
    	slove(b,r,g,nb,nr,ng);
    	printf("%lld\n",ans);
    }
    return 0;
}


# itne me hi thakk gaye?
from bisect import bisect_left, bisect_right

def getf(a, b, c):
    return (a-b)**2 + (b-c)**2 + (a-c)**2
def getcondition(low_arr, mid_arr, high_arr):
    s = 10**20
    for i in mid_arr:
        x_p = bisect_right(high_arr, i)
        x = 10**9
        if(x_p != len(high_arr)):
            x = min(x, high_arr[x_p])
        if(x_p != 0):
            x = min(x, high_arr[x_p-1])
            # print(high_arr, print())

        y = -10**9
        y_ptr = bisect_left(low_arr, i)
        if(y_ptr != 0):
            y = max(y, low_arr[y_ptr-1])
        if (y_ptr != len(low_arr)):
            y = max(y, low_arr[y_ptr])
        # if (i == 1):
        #     print("here : {}, x: {}, y: {}".format(i, x, y))

        curr = getf(i, x, y)
        if curr < s:
            s = curr
    return s
for _ in range(int(input())):
    r,g,b = map(int, input().split())
    red = sorted(list(map(int, input().split())))
    green = sorted(list(map(int, input().split())))
    blue = sorted(list(map(int, input().split())))
    # print(red)
    # print(green)
    # print(blue)
    ans = []
    ans.append(getcondition(red, blue, green))
    ans.append(getcondition(green, blue, red))
    ans.append(getcondition(red, green, blue))
    ans.append(getcondition(blue, green, red))
    ans.append(getcondition(blue, red, green))
    ans.append(getcondition(green, red, blue))
    # print(ans)
    print(min(ans))


import sys
import collections
import threading
import itertools

def main():
    testn = int(input())
    for _ in range(testn):
        nr, ng, nb = map(int, input().split() )
        r = sorted(list(map(int, input().split() )))
        g = sorted(list(map(int, input().split() )))
        b = sorted(list(map(int, input().split() )))
        # AAAAAAAAI forgot to sort :)))
        i, j, k = 0, 0, 0

        ans = (r[i]-g[j])**2 + (g[j] - b[k])**2 + (b[k] - r[i])**2

        permut3 = itertools.permutations( [r,g,b] )

        for first, second, third in permut3:
                    i, j, k = 0, 0, 0
                    #print(first, second,third)

                    for j in range(len(second)):
                        while i < len(first)-1 and first[i+1] <= second[j]: i+=1
                        while k < len(third)-1 and third[k] < second[j]: k+=1

                        tmp = (first[i] - second[j])**2 + (second[j] - third[k])**2 + (third[k]-first[i])**2
                        #print(first[i], second[j], third[k], tmp)
                        if tmp < ans:
                            ans = tmp
        print(ans)

input = sys.stdin.readline
sys.setrecursionlimit(2097152)
main()


#include<iostream>
using namespace std;

int main()
{
      int t;
      cin>>t;
      while(t!=0)
      {
        int n,i;
        cin>>n;
        int a[n];
        for(i=0;i<n;i++)
        {
              cin>>a[i];
        }
        int c=0;
        for(i=1;i<n;i++)
        {
              if(abs(a[i]-a[i-1]>=2))
              {
                    cout<<"YES"<<endl;
                    cout<<i<<" "<<i+1<<endl;
                    c=1;
                    break;
              }
        }
            if(c==0)
            {
                  cout<<"NO"<<endl;
            }
            t--;
      }

      return 0;
}


#include<iostream>
using namespace std;

int main()
{
      int t;
      cin>>t;
      while(t!=0)
      {
        int n,i;
        cin>>n;
        int a[n];
        for(i=0;i<n;i++)
        {
              cin>>a[i];
        }
        int c=0;
        for(i=0;i<n-1;i++)
        {
              if(abs(a[i]-a[i+1]>=2))
              {
                    cout<<"YES"<<endl;
                    cout<<i+1<<" "<<i+2<<endl;
                    c=1;
                    break;
              }
        }
            if(c==0)
            {
                  cout<<"N0"<<endl;
            }
            t--;
      }

      return 0;
}


#include<iostream>
using namespace std;

int main()
{
      int t;
      cin>>t;
      while(t!=0)
      {
        int n,i;
        cin>>n;
        int a[n];
        for(i=0;i<n;i++)
        {
              cin>>a[i];
        }
        int c=0;
        for(i=0;i<n-1;i++)
        {
              if(abs(a[i]-a[i+1]>=2))
              {
                    cout<<"YES"<<endl;
                    cout<<i<<" "<<i+1<<endl;
                    c=1;
                    break;
              }
        }
            if(c==0)
            {
                  cout<<"NO"<<endl;
            }
            t--;
      }

      return 0;
}


#include<iostream>
using namespace std;

int main()
{
      int t;
      cin>>t;
      while(t!=0)
      {
        int n,i;
        cin>>n;
        int a[n];
        for(i=0;i<n;i++)
        {
              cin>>a[i];
        }
        int c=0;
        for(i=0;i<n-1;i++)
        {
              if(abs(a[i]-a[i+1]>=2))
              {
                    cout<<"YES"<<endl;
                    cout<<i+1<<" "<<i+2<<endl;
                    c=1;
                    break;
              }
        }
            if(c==0)
            {
                  cout<<"NO"<<endl;
            }
            t--;
      }

      return 0;
}


#include<iostream>
using namespace std;

int main()
{
      int t;
      cin>>t;
      while(t!=0)
      {
        int n,i;
        cin>>n;
        int a[n];
        for(i=0;i<n;i++)
        {
              cin>>a[i];
        }
        int c=0;
        for(i=1;i<n;i++)
        {
              if(abs(a[i]-a[i-1])>=2)
              {
                    cout<<"YES"<<endl;
                    cout<<i<<" "<<i+1<<endl;
                    c=1;
                    break;
              }
        }
            if(c==0)
            {
                  cout<<"NO"<<endl;
            }
            t--;
      }

      return 0;
}


#include <iostream>
#include<math.h>
using namespace std;
int sktss(int n)
{
        int a[n+2];
        for ( int z=1; z<= n; z++)
        {
            cin >> a[z];
        }
        for( int  i = 1; i <= n/2; i++)
        {
            for( int j = n; j>=n/2+n%2; j--)
            {
                    if(abs(a[j]-a[i])>=n)
                    {
                        cout << "YES" << endl;
                        cout << i << " " <<j <<endl;
                        return 1;

                    }
            }
         }
         cout<<"NO"<<endl;
         return 0;
}
int main()
{
    int t, n;
    cin >> t;
    for ( int o = 1; o <= t; o++)
    {
        cin >> n;
        sktss(n);
    }

    return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
    int t, n;
    cin >> t;
    for ( int o = 1; o <= t; o++)
    {
        cin >> n;
        int a[n];
        bool dd1=true, dd2=true;
        for ( int z=1; z<= n; z++)
        {
            cin >> a[z];
        }
        sort(a+1,a+n);
        for( int  i = 1; i <= n-1; i++)
        {
            for( int j = i+1; j<= n; j++)
            {
                if(a[j]-a[i]>=n)
                {
                    cout << "YES" << endl;
                    cout << i << " " <<j <<endl;
                    dd1=dd2=false;
                    break;
                }
            }
            if(dd2==false)
            {
                break;
            }
        }
        if(dd1==true)
        {
            cout << "NO"<<endl;
        }
    }
    return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
    int t, n;
    cin >> t;
    for ( int o = 1; o <= t; o++)
    {
        cin >> n;
        int a[n];
        bool dd1=true, dd2=true;
        for ( int z=1; z<= n; z++)
        {
            cin >> a[z];
        }
        sort(a+1,a+n);
        for( int  i = 1; i <= n-1; i++)
        {
            for( int j = i+1; j<= n; j++)
            {
                if(a[j]>a[i])
                {
                    if(a[j]-a[i]>=n)
                {
                    cout << "YES" << endl;
                    cout << i << " " <<j <<endl;
                    dd1=dd2=false;
                    break;
                }
                }
                else
                {
                    if(a[i]-a[j]>=n)
                {
                    cout << "YES" << endl;
                    cout << j << " " <<i <<endl;
                    dd1=dd2=false;
                    break;
                }
                }

            }
            if(dd2==false)
            {
                break;
            }
        }
        if(dd1==true)
        {
            cout << "NO"<<endl;
        }
    }
    return 0;
}


#include <iostream>
#include<math.h>
using namespace std;
int sktss(int n)
{
        int a[n];
        for ( int z=1; z<= n; z++)
        {
            cin >> a[z];
        }
        for( int  i = 1; i <= n-1; i++)
        {
            for( int j = i+1; j<=n; j++)
            {
                    if(abs(a[j]-a[i])>=n)
                    {
                        cout << "YES" << endl;
                        cout << i << " " <<j <<endl;
                        return 1;

                    }
            }
         }
         cout<<"NO"<<endl;
         return 1;
}
int main()
{
    int t, n;
    cin >> t;
    for ( int o = 1; o <= t; o++)
    {
        cin >> n;
        sktss(n);
    }

    return 0;
}


#include <iostream>
using namespace std;

int main()
{
    int t, n;
    cin >> t;
    for ( int o = 1; o <= t; o++)
    {
        cin >> n;
        int a[n];
        bool dd1=true, dd2=true;
        for ( int z=1; z<= n; z++)
        {
            cin >> a[z];
        }
        for( int  i = 1; i <= n-1; i++)
        {
            for( int j = i+1; j<= n; j++)
            {
                if(a[j]-a[i]>=n)
                {
                    cout << "YES" << endl;
                    cout << i << " " <<j <<endl;
                    dd1=dd2=false;
                    break;
                }
            }
            if(dd2==false)
            {
                break;
            }
        }
        if(dd1==true)
        {
            cout << "NO"<<endl;
        }
    }
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int t, n;
    cin >> t;
    for ( int o = 1; o <= t; o++)
    {
        cin >> n;
        int a[n];
        bool dd1=true, dd2=true;
        for ( int z=1; z<= n; z++)
        {
            cin >> a[z];
        }
        for( int  i = 1; i <= n/2; i++)
        {
            for( int j = n; j>=n/2; j--)
            {
                if(a[j]>a[i])
                {
                    if(a[j]-a[i]>=2)
                    {
                        cout << "YES" << endl;
                        cout << i << " " <<j <<endl;
                        dd1=dd2=false;
                        break;
                    }
                }
                else
                {
                    if(a[i]-a[j]>=2)
                    {
                        cout << "YES" << endl;
                        cout << i << " " << j <<endl;
                        dd1=dd2=false;
                        break;
                    }
                }
            }
            if(dd2==false)
            {
                break;
            }
        }
        if(dd1==true)
        {
            cout << "NO"<<endl;
        }
    }
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int t, n;
    cin >> t;
    for ( int o = 1; o <= t; o++)
    {
        cin >> n;
        int a[n+1];
        bool dd1=true, dd2=true;
        for ( int z=1; z<= n; z++)
        {
            cin >> a[z];
        }
        for( int  i = 1; i <= n; i++)
        {
            for( int j = n; j>=n; j--)
            {
                if(a[j]>a[i])
                {
                    if(a[j]-a[i]>=n)
                    {
                        cout << "YES" << endl;
                        cout << i << " " <<j <<endl;
                        dd1=dd2=false;
                        break;
                    }
                }
                else
                {
                    if(a[i]-a[j]>=n)
                    {
                        cout << "YES" << endl;
                        cout << i << " " << j <<endl;
                        dd1=dd2=false;
                        break;
                    }
                }
            }
            if(dd2==false)
            {
                break;
            }
        }
        if(dd1==true)
        {
            cout << "NO"<<endl;
        }
    }
    return 0;
}


#include <iostream>
#include<math.h>
using namespace std;
void sktss(int n)
{
        int a[n+1];
        for ( int i=1; i<= n; i++)
        {
            cin >> a[i];
        }
        for( int  i = 1; i <= n-1; i++)
        {
            for( int j = i+1; j<=n; j++)
            {
                    if(abs(a[j]-a[i])>=n)
                    {
                        cout << "YES" << endl;
                        cout << i << " " <<j <<endl;
                        return ;
                    }
            }
         }
         cout<<"NO"<<endl;
         return ;
}
int main()
{
    int t;
    cin >> t;
    for ( int o = 1; o <= t; o++)
    {
        int n;
        cin >> n;
        sktss(n);
    }
    return 0;
}


#include <iostream>
#include <stdlib.h>

using namespace std;

int main()
{
    int t, n;
    cin >> t;
    for ( int o = 1; o <= t; o++)
    {
        cin >> n;
        int a[n+1];
        bool dd1=true, dd2=true;
        for ( int z=1; z<= n; z++)
        {
            cin >> a[z];
        }
        for( int  i = 1; i<=n-1; i++)
        {
            for( int j = i+1; j<=n; j++)
            {
                    if(abs(a[j]-a[i])>=n)
                    {
                        cout << "YES" << endl;
                        cout << i << " " <<j <<endl;
                        dd1=dd2=false;
                        break;
                    }
            }
            if(dd2==false)
            {
                break;
            }
        }
        if(dd1==true)
        {
            cout << "NO"<<endl;
        }
    }
    return 0;
}


#include <iostream>
#include<math.h>
using namespace std;
void sktss(int n)
{
        int a[n+2];
        for ( int i=1; i<= n; i++)
        {
            cin >> a[i];
        }
        for( int  i = 1; i <= n-1; i++)
        {
            for( int j = i+1; j<=n; j++)
            {
                    if(abs(a[j]-a[i])>=n)
                    {
                        cout << "YES" << endl;
                        cout << i << " " <<j <<endl;
                        return ;

                    }
            }
         }
         cout<<"NO"<<endl;
         return ;
}
int main()
{
    int t;
    cin >> t;
    for ( int o = 1; o <= t; o++)
    {
        int n;
        cin >> n;
        sktss(n);
    }

    return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
    int t, n;
    cin >> t;
    for ( int o = 1; o <= t; o++)
    {
        cin >> n;
        int a[n];
        bool dd1=true, dd2=true;
        for ( int z=1; z<= n; z++)
        {
            cin >> a[z];
        }
        //sort(a+1,a+n);
        for( int  i = 1; i <= n-1; i++)
        {
            for( int j = i+1; j<= n; j++)
            {
                if(a[j]-a[i]>=n)
                {
                    cout << "YES" << endl;
                    cout << i << " " <<j <<endl;
                    dd1=dd2=false;
                    break;
                }
            }
            if(dd2==false)
            {
                break;
            }
        }
        if(dd1==true)
        {
            cout << "NO"<<endl;
        }
    }
    return 0;
}


#include <iostream>
#include <stdlib.h>

using namespace std;

int main()
{
    int t, n;
    cin >> t;
    for ( int o = 1; o <= t; o++)
    {
        cin >> n;
        int a[n+1];
        bool dd1=true, dd2=true;
        for ( int z=1; z<= n; z++)
        {
            cin >> a[z];
        }
        for( int  i = 1; i<=n; i++)
        {
            for( int j = 1; j<=n; j++)
            {
                    if(abs(a[j]-a[i])>=n)
                    {
                        cout << "YES" << endl;
                        cout << i << " " <<j <<endl;
                        dd1=dd2=false;
                        break;
                    }
            }
            if(dd2==false)
            {
                break;
            }
        }
        if(dd1==true)
        {
            cout << "NO"<<endl;
        }
    }
    return 0;
}


#include <iostream>
#include<math.h>
using namespace std;
int sktss(int n)
{
        int a[n+2];
        for ( int i=1; i<= n; i++)
        {
            cin >> a[i];
        }
        for( int  i = 1; i <= n-1; i++)
        {
            for( int j = i+1; j<=n; j++)
            {
                    if(abs(a[j]-a[i])>=n)
                    {
                        cout << "YES" << endl;
                        cout << i << " " <<j <<endl;
                        return 1;

                    }
            }
         }
         cout<<"NO"<<endl;
         return 1;
}
int main()
{
    int t, n;
    cin >> t;
    for ( int o = 1; o <= t; o++)
    {
        cin >> n;
        sktss(n);
    }

    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int t, n;
    cin >> t;
    for ( int o = 1; o <= t; o++)
    {
        cin >> n;
        int a[n];
        bool dd1=true, dd2=true;
        for ( int z=1; z<= n; z++)
        {
            cin >> a[z];
        }
        for( int  i = 1; i <= n/2; i++)
        {
            for( int j = n; j>=n/2; j--)
            {
                if(a[j]>a[i])
                {
                    if(a[j]-a[i]>=n)
                    {
                        cout << "YES" << endl;
                        cout << i << " " <<j <<endl;
                        dd1=dd2=false;
                        break;
                    }
                }
                else
                {
                    if(a[i]-a[j]>=n)
                    {
                        cout << "YES" << endl;
                        cout << i << " " << j <<endl;
                        dd1=dd2=false;
                        break;
                    }
                }
            }
            if(dd2==false)
            {
                break;
            }
        }
        if(dd1==true)
        {
            cout << "NO"<<endl;
        }
    }
    return 0;
}


#include <iostream>
#include <stdlib.h>

using namespace std;

int main()
{
    int t, n;
    cin >> t;
    for ( int o = 1; o <= t; o++)
    {
        cin >> n;
        int a[n+1];
        bool dd1=true, dd2=true;
        for ( int z=1; z<= n; z++)
        {
            cin >> a[z];
        }
        for( int  i = 1; i<=n; i++)
        {
            for( int j = n; j>=1; j--)
            {
                    if(abs(a[j]-a[i])>=n)
                    {
                        cout << "YES" << endl;
                        cout << i << " " <<j <<endl;
                        dd1=dd2=false;
                        break;
                    }
            }
            if(dd2==false)
            {
                break;
            }
        }
        if(dd1==true)
        {
            cout << "NO"<<endl;
        }
    }
    return 0;
}


#include <iostream>
#include<math.h>
using namespace std;

int main()
{
    int t, n;
    cin >> t;
    for ( int o = 1; o <= t; o++)
    {
        cin >> n;
        int a[n+2];
        bool dd1=true, dd2=true;
        for ( int z=1; z<= n; z++)
        {
            cin >> a[z];
        }
        for( int  i = 1; i <= n/2+n%2; i++)
        {
            for( int j = n; j>=n/2; j--)
            {
                    if(abs(a[j]-a[i])>=n)
                    {
                        cout << "YES" << endl;
                        cout << i << " " <<j <<endl;
                        dd1=dd2=false;
                        break;
                    }
            }

            if(dd2==false)
            {
                break;
            }
            }
        if(dd1==true)
        {
            cout << "NO"<<endl;
        }
    }

    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int t, n;
    cin >> t;
    for ( int o = 1; o <= t; o++)
    {
        cin >> n;
        int a[n];
        bool dd1=true, dd2=true;
        for ( int z=1; z<= n; z++)
        {
            cin >> a[z];
        }
        for( int  i = 1; i <= n-1; i++)
        {
            for( int j = i+1; j<= n; j++)
            {
                if(a[j]>a[i])
                {
                    if(a[j]-a[i]>=n)
                {
                    cout << "YES" << endl;
                    cout << i << " " <<j <<endl;
                    dd1=dd2=false;
                    break;
                }
                }
                else
                {
                    if(a[i]-a[j]>=n)
                {
                    cout << "YES" << endl;
                    cout << i << " " << j <<endl;
                    dd1=dd2=false;
                    break;
                }
                }

            }
            if(dd2==false)
            {
                break;
            }
        }
        if(dd1==true)
        {
            cout << "NO"<<endl;
        }
    }
    return 0;
}


#include <iostream>
#include <stdlib.h>
#include <stdio.h>

using namespace std;

int main()
{
    //freopen("test.inp","r",stdin);
    int t, i, n;
    int a[200001];
    cin >> t;
    for (int h = 1; h <= t; h++)
    {
        cin >> n;
        for (i = 1; i <= n; i++) cin >> a[i];
        bool tmp = false;
        for (i = 1; i <= n-1; i++) if (abs(a[i]-a[i+1]) >= 2)
        {
            tmp = true;
            cout << "YES" << endl;
            cout << i << " " << i+1;
            break;
        }
        if (tmp == false) cout << "NO";
        if (h < t) cout << endl;
    }
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int t, n;
    cin >> t;
    for ( int o = 1; o <= t; o++)
    {
        cin >> n;
        int a[n];
        bool dd1=true, dd2=true;
        for ( int z=1; z<= n; z++)
        {
            cin >> a[z];
        }
        for( int  i = 1; i <= n; i++)
        {
            for( int j = n; j>=n; j--)
            {
                if(a[j]>a[i])
                {
                    if(a[j]-a[i]>=n)
                    {
                        cout << "YES" << endl;
                        cout << i << " " <<j <<endl;
                        dd1=dd2=false;
                        break;
                    }
                }
                else
                {
                    if(a[i]-a[j]>=n)
                    {
                        cout << "YES" << endl;
                        cout << i << " " << j <<endl;
                        dd1=dd2=false;
                        break;
                    }
                }
            }
            if(dd2==false)
            {
                break;
            }
        }
        if(dd1==true)
        {
            cout << "NO"<<endl;
        }
    }
    return 0;
}


#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;

void solve() {

	int n;
	cin >> n;

	int a[200009];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	int max = -1, min = 0x7fffffff;
	int t1 = 0, t2 = 0;
	for (int i = 0; i < n; i++) {

		if (max < a[i]) {
			max = a[i];
			t1 = i;
		}
		if (min > a[i]) {
			min = a[i];
			t2 = i;
		}
	}

	if (t1 > t2) {
		swap(t1, t2);
	}

	if (max - min >= n) {
		cout << "YES" << endl;
		cout << t1 + 1 << " " << t2 + 1 << endl;
	}
	else {
		cout << "NO" << endl;
	}
}

int main() {
	int T;
	cin >> T;
	while (T--) {
		solve();
	}
	return 0;
}


#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;
int a[200009];
void solve() {

	int n;
	cin >> n;

	for (int i = 0; i < n; i++) {
		scanf_s("%d", &a[i]);
	}

	sort(a, a + n);

	if (a[n - 1] - a[0] >= n) {
		cout << "YES" << endl;
		cout << 1 << " " << n << endl;
	}
	else {
		cout << "NO" << endl;
	}
}

int main() {
	ll T;
	cin >> T;
	while (T--) {
		solve();
	}
	return 0;
}


#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;
int a[200009];
void solve() {

	int n;
	cin >> n;

	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}

	sort(a, a + n);

	if (a[n - 1] - a[0] >= n) {
		cout << "YES" << endl;
		cout << 1 << " " << n << endl;
	}
	else {
		cout << "NO" << endl;
	}
}

int main() {
	ll T;
	cin >> T;
	while (T--) {
		solve();
	}
	return 0;
}


#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;

void solve() {

	int n;
	cin >> n;

	int a[200009];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	int max = -1, min = 0x7fffffff;
	for (int i = 0; i < n; i++) {

		if (max < a[i]) {
			max = a[i];
		}
		if (min > a[i]) {
			min = a[i];
		}
	}

	if (max - min >= n) {
		cout << "YES" << endl;
		cout << 1 << " " << n << endl;
	}
	else {
		cout << "NO" << endl;
	}
}

int main() {
	int T;
	cin >> T;
	while (T--) {
		solve();
	}
	return 0;
}


#include<iostream>
#include<cmath>
#define ll long long
using namespace std;

void solve() {
	bool ok = false;
	int re = 0;
	int n;
	cin >> n;
	int x, y;
	cin >> x;
	for (int i = 1; i < n; i++) {
		cin >> y;
		if (abs(x - y) > 1) {
			ok = true;
			re = i;
		}
		x = y;
	}
	if (ok) {
		cout << "YES" << endl;
		cout << re << " " << re + 1 << endl;
	}
	else {
		cout << "NO" << endl;
	}
}

int main() {
	int T;
	cin >> T;
	while (T--) {
		solve();
	}
	return 0;
}


#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;

void solve() {

	int n;
	cin >> n;

	int a[200009];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	int max = -1, min = 0x7fffffff;
	for (int i = 0; i < n; i++) {

		if (max < a[i]) {
			max = a[i];
		}
		if (min > a[i]) {
			min = a[i];
		}
	}

	if (t1 > t2) {
		swap(t1, t2);
	}

	if (max - min >= n) {
		cout << "YES" << endl;
		cout << 1 << " " << n << endl;
	}
	else {
		cout << "NO" << endl;
	}
}

int main() {
	int T;
	cin >> T;
	while (T--) {
		solve();
	}
	return 0;
}


#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;
ll a[200009];
void solve() {

	ll n;
	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	ll max = -1, min = 1000000000000;
	for (int i = 0; i < n; i++) {

		if (max < a[i]) {
			max = a[i];
		}
		if (min > a[i]) {
			min = a[i];
		}
	}

	if (max - min >= n) {
		cout << "YES" << endl;
		cout << 1 << " " << n << endl;
	}
	else {
		cout << "NO" << endl;
	}
}

int main() {
	ll T;
	cin >> T;
	while (T--) {
		solve();
	}
	return 0;
}


#include <iostream>

using namespace std;
long t, n, a[200003], i, j, mi, mx, k, x;
bool cor;
int main()
{
    cin>>t;
    for (i=1;i<=t;i++)
    {
        cor=false;
        cin>>n;
        for (j=1;j<=n;j++)
        {
            cin>>a[j];
        }
        for (j=1;j<=n-1;j++)
        {
            for (k=j+1;k<+n;k++)
            {
                mx=-1;
                mi=1000000001;
               for (x=j;x<=k;x++)
               {
                   if (mx<a[x]) mx=a[x];
                   if (mi>a[x]) mi=a[x];
               }
               if (mx-mi>=k-j+1)
               {
                   cor=true;
                   cout<<"YES"<<'\n'<<j<<" "<<k<<'\n';
                   break;
               }
            }
            if (cor==true) break;
        }
        if (cor==false) cout<<"NO"<<'\n';
    }
    return 0;
}


#include <iostream>

using namespace std;
long t, n, a[200003], i, j, mi, mx, k, x;
bool cor;
int main()
{
    cin>>t;
    for (i=1;i<=t;i++)
    {
        cor=false;
        cin>>n;
        for (j=1;j<=n;j++)
        {
            cin>>a[j];
        }
        for (j=1;j<=n-1;j++)
        {
            for (k=j+1;k<+n;k++)
            {
                mx=0;
                mi=1000000001;
               for (x=j;x<=k;x++)
               {
                   if (mx<a[x]) mx=a[x];
                   if (mi>a[x]) mi=a[x];
               }
               if (mx-mi>=k-j+1)
               {
                   cor=true;
                   cout<<"YES"<<'\n'<<j<<" "<<k<<'\n';
                   break;
               }
            }
            if (cor==true) break;
        }
        if (cor==false) cout<<"NO"<<'\n';
    }
    return 0;
}


#include <iostream>

using namespace std;
long t, n, a[200003], i, j, la, lb, mi, mx, k;
bool cor;
int main()
{
    cin>>t;
    for (i=1;i<=t;i++)
    {
        cor=false;
        cin>>n;
        for (j=1;j<=n;j++)
        {
            cin>>a[j];
        }
        la=1;
        lb=n;
        mx=0;
        mi=1000000001;
        for (j=1;j<=n;j++)
        {
            for (k=la;k<=lb;k++)
            {
                if (mx<a[k]) mx=a[k];
                if (mi>a[k]) mi=a[k];
            }
            if (mx-mi>=lb-la+1)
            {
                cor=true;

            }

            if (cor==true)
                {
                    cout<<"YES"<<'\n'<<la<<" "<<lb<<'\n';
                    break;
                }
        }
        if (cor==false)
            cout<<"NO"<<'\n';
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
int a[200010];
int main()
{
    int t,n,l,r;
    cin>>t;
    while(t--)
    {
        cin>>n;
        for(int i=1; i<=n; i++)
            cin>>a[i];
        int flag=0;
        for(int i=1; i<n; i++)
        {
            if(abs(a[i+1]-a[i])>=2)
            {
                flag=1;
                l=i;
                r=i+1;
                break;
            }
        }
        if(flag==0)
            cout<<"NO"<<endl;
        else
        {
            cout<<"YES"<<endl;
            cout<<l<<" "<<r<<endl;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int a[200005];

int main()
{
    int t,n,minn,maxx;
    cin>>t;
    while(t--)
    {
        cin>>n;
        for(int i=1;i<=n; i++)
        cin>>a[i];
        sort(a+1,a+1+n);
        if((a[n]-a[1])>=n)
        {
            cout<<"YES"<<endl;
            for(int i=1; i<=n; i++)
            {
                if(a[i]>=1)
                {
                    minn=a[i];
                    break;
                }
            }
            for(int i=n;i>=1; i--)
            {
                if(a[i]<=n)
                {
                    maxx=a[i];
                    break;
                }
            }
            cout<<minn<<" "<<maxx<<endl;
        }
        else
        cout<<"NO"<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
int a[200010];
int main()
{
    int t,n;
    cin>>t;
    while(t--)
    {
        cin>>n;
        int minn,maxx;
        for(int i=1; i<=n; i++)
            cin>>a[i];
        minn=a[1];
        maxx=a[1];
        for(int i=2; i<=n; i++)
        {
            if(a[i]<minn)
                minn=a[i];
            if(a[i]>maxx)
                maxx=a[i];
        }
        if((maxx-minn)>=n)
        {
            cout<<"YES"<<endl;
            for(int i=1; i<n; i++)
            {
                if(abs(a[i+1]-a[i])>=2)
                {
                    cout<<a[i]<<" "<<a[i+1]<<endl;
                    break;
                }
            }
        }
        else
            cout<<"NO"<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
int a[200010];
int main()
{
    int t,n;
    cin>>t;
    while(t--)
    {
        cin>>n;
        int minn,maxx;
        for(int i=1; i<=n; i++)
            cin>>a[i];
        minn=a[1];
        maxx=a[1];
        for(int i=2; i<=n; i++)
        {
            if(a[i]<minn)
                minn=a[i];
            if(a[i]>maxx)
                maxx=a[i];
        }
        if((maxx-minn)>=n)
        {
            cout<<"YES"<<endl;
            for(int i=1; i<n; i++)
            {
                if(abs(a[i+1]-a[i])>=2)
                {
                    cout<<i<<" "<<i+1<<endl;
                    break;
                }
            }
        }
        else
            cout<<"NO"<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int a[200005];

int main()
{
    int t,n;
    cin>>t;
    while(t--)
    {
        cin>>n;
         for(int i=1; i<=n; i++)
        {
            cin>>a[i];
        }
        int minn=a[1];
        int maxx=a[1];
        for(int i=1; i<=n; i++)
        {
            if(a[i]<minn)minn=a[i];
            if(a[i]>maxx)maxx=a[i];
        }
         int sum=maxx-minn;
         if(sum>=n)
         {
             cout<<"YES"<<endl;
             cout<<1<<" "<<n<<endl;
         }
         else
            cout<<"NO"<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
int a[200010];
int main()
{
    int t,n,l,r;
    cin>>t;
    while(t--)
    {
        cin>>n;
        for(int i=1; i<=n; i++)
            cin>>a[i];
        int flag=0;
        for(int i=1; i<n; i++)
        {
            if(abs(a[i+1]-a[i])>=2)
            {
                flag=1;
                l=a[i];
                r=a[i+1];
                break;
            }
        }
        if(flag==0)
            cout<<"NO"<<endl;
        else
        {
            cout<<"YES"<<endl;
            cout<<l<<" "<<r<<endl;
        }
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
int a[200010];
int main()
{
    int t,n,l,r;
    cin>>t;
    while(t--)
    {
        cin>>n;
        for(int i=1; i<=n; i++)
        cin>>a[i];
        int flag=0;
        for(int i=2; i<=n; i++)
        {
            if(abs(a[i]-a[i-1])>=2&&i>=2)
            {
                flag=1;
                l=a[i-1];
                r=a[i];
                break;
            }
        }
        if(flag==0)
            cout<<"NO"<<endl;
        else
        {
            cout<<"YES"<<endl;
            cout<<l<<" "<<r<<endl;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int a[200005];

int main()
{
    int T;

    cin >>T;

    while(T--)
    {

        int n;

        scanf("%d",&n);

        int flag = 0,l,r;

        for(int i = 1; i <= n; i++)
        {

            scanf("%d",&a[i]);

            if(i > 1 && abs(a[i]-a[i-1]) >= 2 &&flag == 0)
            {

                l = i-1;

                r = i;

                flag = 1;

            }

        }

        if(flag == 0)cout<<"NO"<<endl;

        else
        {

            cout <<"YES"<<endl;

            cout <<l <<' ' <<r <<endl;

        }

    }

    return 0;

}


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

int main()
{
    int test,n,val=0;
    long int arr[200005];
    cin>>test;
    for(int i=0; i<test; i++)
    {
        cin>>n;
        for(int j=0; j<n; j++)
        {
            cin>>arr[j];
        }
        sort(arr,arr+n);
        val = (arr[n-1]-arr[0]);
        if(val>=n)
        {
            cout<<"YES"<<endl;
            cout<<1<<" "<<n-1<<endl;
        }
        else
            cout<<"NO"<<endl;
    }

}


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

int main()
{
    int test,n,val=0;
    long int arr[200005];
    cin>>test;
    for(int i=0; i<test; i++)
    {
        cin>>n;
        bool check = false;

        for(int j=0; j<n; j++)
        {
            cin>>arr[j];
        }
        for(int j=0; j<n; j++)
        {
            for(int k=j+1; k<n; k++)
            {
                if(abs(arr[j]-arr[k])>=n)
                {
                    cout<<"YES"<<endl;
                    cout<<min(j+1,k+1)<<" "<<max(j+1,k+1)<<endl;
                    check = true;
                    break;
                }

            }
            break;
        }
        if(check==false)
        {
            cout<<"NO"<<endl;
        }

    }

}


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

int main()
{
    int test,n,val=0;
    long int arr[200005];
    cin>>test;

    for(int i=0; i<test; i++)
    {
        cin>>n;

        for(int j=0; j<n; j++)
        {
            cin>>arr[j];
        }
        sort(arr,arr+n);
        val = arr[n-1]-arr[0];
        if(val>=n)
        {
            cout<<"YES"<<endl;
            cout<<1<<" "<<n<<endl;

        }
        else
        {
            cout<<"NO"<<endl;
        }

    }

}


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

int main()
{
    int test,n,val=0;
    long int arr[200005]={0};
    cin>>test;
    for(int i=0; i<test; i++)
    {
        cin>>n;
        bool check = false;
        for(int j=0; j<n; j++)
        {
            cin>>arr[j];
        }
        for(int j=0; j<n; j++)
        {
            for(int k=0; k<n; k++)
            {
                if(abs(arr[j]-arr[k])>=n)
                {
                    cout<<"YES"<<endl;
                    cout<<min(j+1,k+1)<<" "<<max(j+1,k+1)<<endl;
                           check = true;
                           break;
                }

            }
            if(check==false)
            {
                continue;
            }
            else if(check==true)
            {
                break;
            }
        }
        if(check==false)
        {
            cout<<"NO"<<endl;
        }
        memset(arr,0,sizeof(arr));

    }

}


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

int main()
{
    int test,n,val=0;
    long int arr[200005];
    cin>>test;
    while(test--)
    {
        cin>>n;
        bool check = false;
        for(int j=1; j<=n; j++)
        {
            cin>>arr[j];
        }
        for(int j=1; j<n; j++)
        {
            if(abs(arr[j]-arr[j+1])>=2)
            {
                cout<<"YES"<<endl;
                cout<<j<<" "<<j+1<<endl;
                check = true;
                break;
            }

        }

    if(check==false)
    {
        cout<<"NO"<<endl;
    }
}
}


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

int main()
{
    int test,n,val=0;
    long int arr[200005];
    cin>>test;
    for(int i=0; i<test; i++)
    {
        cin>>n;
        bool check = false;

        for(int j=0; j<n; j++)
        {
            cin>>arr[j];
        }
        for(int j=0; j<n; j++)
        {
            for(int k=j+1; k<n; k++)
            {
                if(abs(arr[j]-arr[k])>=n)
                {
                    cout<<"YES"<<endl;
                    cout<<j+1<<" "<<k+1<<endl;
                    check = true;
                    break;
                }

            }
            break;
        }
        if(check==false)
        {
            cout<<"NO"<<endl;
        }

    }

}


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

int main()
{
    int test,n,val=0;
    long int arr[200005];
    cin>>test;
    for(int i=0; i<test; i++)
    {
        cin>>n;
        for(int j=0; j<n; j++)
        {
            cin>>arr[j];
        }
        sort(arr,arr+n);
        val = (arr[n-1]-arr[0]);
        if(val>=n)
        {
            cout<<"YES"<<endl;
            cout<<1<<" "<<n<<endl;
        }
        else
            cout<<"NO"<<endl;
    }

}


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

int main()
{
    int test,n,val=0;
    long int arr[200005];
    cin>>test;
    for(int i=0; i<test; i++)
    {
        cin>>n;
        bool check = false;
        for(int j=0; j<n; j++)
        {
            cin>>arr[j];
        }
        for(int j=0; j<n; j++)
        {
            for(int k=0; k<n; k++)
            {
                if(abs(arr[j]-arr[k])>=n)
                {
                    cout<<"YES"<<endl;
                    cout<<min(j+1,k+1)<<" "<<max(j+1,k+1)<<endl;
                           check = true;
                           break;
                }

            }
            if(check==false)
            {
                continue;
            }
            else if(check==true)
            {
                break;
            }
        }
        if(check==false)
        {
            cout<<"NO"<<endl;
        }

    }

}


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

int main()
{
    int test,n,val=0;
    long int arr[200005]={0};
    cin>>test;
    for(int i=0; i<test; i++)
    {
        cin>>n;
        bool check = false;
        for(int j=0; j<n; j++)
        {
            cin>>arr[j];
        }
        for(int j=0; j<n; j++)
        {
            for(int k=0; k<n; k++)
            {
                if(abs(arr[j]-arr[k])>=2)
                {
                    cout<<"YES"<<endl;
                    cout<<min(j+1,k+1)<<" "<<max(j+1,k+1)<<endl;
                           check = true;
                           break;
                }

            }
            if(check==false)
            {
                continue;
            }
            else if(check==true)
            {
                break;
            }
        }
        if(check==false)
        {
            cout<<"NO"<<endl;
        }
        memset(arr,0,sizeof(arr));

    }

}


#include <stdio.h>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#pragma GCC optimize(2)

#define mm(i,v) memset(i,v,sizeof i);
#define mp(a, b) make_pair(a, b)
#define one first
#define two second

using namespace std;
typedef long long ll;
typedef pair<int, int > PII;

const int N = 2e5 + 5, mod = 1e9 + 9, INF = 0x3f3f3f3f;
ll t, n, Min, Max, pos1, pos2;
int a[N];

int main()
{
	cin >> t;
	while (t--) {
		Min = mod, Max = -1;
		cin >> n;
		for (int i = 1; i <= n; ++i) {
			scanf("%lld", &a[i]);
			if (a[i] > Max) {
				pos1 = i;
				Max = a[i];
			} else if (a[i] < Min) {
				pos2 = i;
				Min = a[i];
			}
		}
		if (Max - Min < n) {
			puts("NO");
		} else {
			puts("YES");
			cout << pos1 << " " << pos2 << endl;
		}
	}
}


#include <stdio.h>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#pragma GCC optimize(2)

#define mm(i,v) memset(i,v,sizeof i);
#define mp(a, b) make_pair(a, b)
#define one first
#define two second

using namespace std;
typedef long long ll;
typedef pair<int, int > PII;

const int N = 2e5 + 5, mod = 1e9 + 9, INF = 0x3f3f3f3f;
ll t, n, Min, Max, pos1, pos2;
int a[N];

int main()
{
	cin >> t;
	while (t--) {
		Min = mod, Max = -1;
		cin >> n;
		for (int i = 1; i <= n; ++i) {
			scanf("%lld", &a[i]);
			if (a[i] > Max) {
				pos1 = i;
				Max = a[i];
			}
			if (a[i] < Min) {
				pos2 = i;
				Min = a[i];
			}
		}
//		cout << Min << endl;
//		cout << Max << endl;
		if (Max - Min < n) {
			puts("NO");
		} else {
			puts("YES");
			cout << min(pos1, pos2) << " " << max(pos1, pos2) << endl;
		}
	}
}


 #include <stdio.h>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#pragma GCC optimize(2)

#define mm(i,v) memset(i,v,sizeof i);
#define mp(a, b) make_pair(a, b)
#define one first
#define two second

using namespace std;
typedef long long ll;
typedef pair<int, int > PII;

const int N = 2e5 + 5, mod = 1e9 + 9, INF = 0x3f3f3f3f;
int t, n, Min, Max, pos1, pos2;
int a[N];

int main()
{
	cin >> t;
	while (t--) {
		Min = INF, Max = -INF;
		cin >> n;
		for (int i = 1; i <= n; ++i) {
			scanf("%d", &a[i]);
			if (a[i] > Max) {
				pos1 = i;
				Max = a[i];
			}
			if (a[i] < Min) {
				pos2 = i;
				Min = a[i];
			}
		}
			if (Max - Min < n) {
				puts("NO");
			} else {
				puts("YES");
				printf("1 %d\n", n);
			}
	}
}


#include <stdio.h>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#pragma GCC optimize(2)

#define mm(i,v) memset(i,v,sizeof i);
#define mp(a, b) make_pair(a, b)
#define one first
#define two second

using namespace std;
typedef long long ll;
typedef pair<int, int > PII;

const int N = 2e5 + 5, mod = 1e9 + 9, INF = 0x3f3f3f3f;
int t, n, Min, Max, pos1, pos2;
int a[N];

int main()
{
	cin >> t;
	while (t--) {
		Min = INF, Max = -INF;
		cin >> n;
		for (int i = 1; i <= n; ++i) {
			scanf("%d", &a[i]);
			if (a[i] > Max) {
				pos1 = i;
				Max = a[i];
			}
			if (a[i] < Min) {
				pos2 = i;
				Min = a[i];
			}
		}
		if (Max - Min < n) {
			puts("NO");
		} else {
			puts("YES");
			printf("%d %d\n", min(pos1, pos2), pos2 + pos1 - min(pos1, pos2));
		}
	}
}


 #include <stdio.h>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#pragma GCC optimize(2)

#define mm(i,v) memset(i,v,sizeof i);
#define mp(a, b) make_pair(a, b)
#define one first
#define two second

using namespace std;
typedef long long ll;
typedef pair<int, int > PII;

const int N = 2e5 + 5, mod = 1e9 + 9, INF = 0x3f3f3f3f;
int t, n, Min, Max, tmp;

int main()
{
	cin >> t;
	while (t--) {
		Min = mod, Max = -1;
		cin >> n;
		for (int i = 1; i <= n; ++i) {
			scanf("%d", &tmp);
			if (tmp > Max)
				Max = tmp;
			if (tmp < Min)
				Min = tmp;
		}
		if (Max - Min < n) {
			puts("NO");
		} else {
			puts("YES");
			cout << "1 " << n << endl;
//			printf("1 %d\n", n);
		}
	}
}


 #include <stdio.h>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#pragma GCC optimize(2)

#define mm(i,v) memset(i,v,sizeof i);
#define mp(a, b) make_pair(a, b)
#define one first
#define two second

using namespace std;
typedef long long ll;
typedef pair<int, int > PII;

const int N = 2e5 + 5, mod = 1e9 + 9, INF = 0x3f3f3f3f;
int t, n, Min, Max, pos1, pos2;
int a[N];

int main()
{
	cin >> t;
	while (t--) {
		Min = INF, Max = -INF;
		cin >> n;
		for (int i = 1; i <= n; ++i) {
			scanf("%d", &a[i]);
			if (a[i] > Max) {
				pos1 = i;
				Max = a[i];
			}
			if (a[i] < Min) {
				pos2 = i;
				Min = a[i];
			}
		}
			if (Max - Min < n) {
				puts("NO");
			} else {
				puts("YES");
				printf("%d %d\n", pos1, pos2);
			}
	}
}


#include <stdio.h>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#pragma GCC optimize(2)

#define mm(i,v) memset(i,v,sizeof i);
#define mp(a, b) make_pair(a, b)
#define one first
#define two second

using namespace std;
typedef long long ll;
typedef pair<int, int > PII;

const int N = 2e5 + 5, mod = 1e9 + 9, INF = 0x3f3f3f3f;
ll t, n, Min, Max, pos1, pos2;
int a[N];

int main()
{
	cin >> t;
	while (t--) {
		Min = mod, Max = -1;
		cin >> n;
		for (int i = 1; i <= n; ++i) {
			scanf("%lld", &a[i]);
			if (a[i] > Max) {
				pos1 = i;
				Max = a[i];
			} else if (a[i] < Min) {
				pos2 = i;
				Min = a[i];
			}
		}
		if (Max - Min < n) {
			puts("NO");
		} else {
			puts("YES");
			for (int i = 1; i <= n; ++i) {
				printf("%d ", i);
			}
			puts("");
		}
	}
}


#include <stdio.h>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#pragma GCC optimize(2)

#define mm(i,v) memset(i,v,sizeof i);
#define mp(a, b) make_pair(a, b)
#define one first
#define two second

using namespace std;
typedef long long ll;
typedef pair<int, int > PII;

const int N = 2e5 + 5, mod = 1e9 + 9, INF = 0x3f3f3f3f;
int t, n, Min, Max, pos1, pos2;
int a[N];

int main()
{
	cin >> t;
	while (t--) {
		cin >> n;
		bool flag = 0;
		for (int i = 1; i <= n; ++i) {
			scanf("%d", &a[i]);
			if (i == 1 || flag == 1) {
				continue;
			}
			if (abs(a[i] - a[i - 1]) >= 2) {
				flag = 1;
				pos1 = i - 1;
				pos2 = i;
			}
		}
		if (flag) {
			puts("YES");
			cout << pos1 << " " << pos2 << endl;
		} else {
			puts("NO");
		}
	}
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<utility>
using namespace std;
int main(){
    int t{0};
    cin>>t;
    while(t--){
        int n{0};
        cin>>n;
        vector<pair<long long int,int>> vec(n);
        for(int i=0;i<n;i++){
            cin>>vec[i].first;
            vec[i].second=i;
        }
        int a{-1},b{-1};
        bool flag=false;
        sort(vec.begin(),vec.end());
        for(int j=0;j<n-1;j++){
            if(j!=0 && vec[j].first==vec[j-1].first)
            continue;
        for(int i=n-1;i>j;i--){
            int z=vec[i].second-vec[j].second;
            if(z<0)
            z=-z;
            z++;
            if(vec[i].first-vec[j].first>=z){
                a=vec[i].second;
                b=vec[j].second;
                flag=true;
                break;
            }
        }
            if(flag)
            break;
        }
        if(a<b){
            int x=a;
            a=b;
            b=x;
        }
        if(a==-1 && b==-1){
            cout<<"NO"<<endl;
        }else{
            cout<<"YES"<<endl;
            cout<<b+1<<" "<<a+1<<endl;
        }
    }

    return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<utility>
using namespace std;
int main(){
    int t{0};
    cin>>t;
    while(t--){
        int n{0};
        cin>>n;
        vector<pair<long long int,int>> vec(n);
        for(int i=0;i<n;i++){
            cin>>vec[i].first;
            vec[i].second=i;
        }
        int a{-1},b{-1};
        sort(vec.begin(),vec.end());
        for(int i=n-1;i>0;i--){
            int z=vec[i].second-vec[0].second;
            if(z<0)
            z=-z;
            z++;
            if(vec[i].first-vec[0].first>=z){
                a=vec[i].second;
                b=vec[0].second;
                break;
            }
        }
        if(a<b){
            int x=a;
            a=b;
            b=x;
        }
        if(a==-1 && b==-1){
            cout<<"NO"<<endl;
        }else{
            cout<<"YES"<<endl;
            cout<<b+1<<" "<<a+1<<endl;
        }
    }

    return 0;
}


#include<iostream>
#include<algorithm>
#include<numeric>
#include<vector>
#include<utility>
using namespace std;
int main(){
    int t{0};
    cin>>t;
    while(t--){
        int n{0};
        cin>>n;
        vector<long long int> vec(n);
        int a=-1,b=-1;
        for(int i=0;i<n;i++){
            cin>>vec[i];
        }
        for(int i=1;i<n;i++){
            long long int z=vec[i]-vec[i-1];
            if(z<0)
            z=-z;
            if(z>=2){
                a=i-1;
                b=i;
                break;
            }
        }
        if(a==-1 && b==-1){
            cout<<"NO"<<endl;
        }else{
            cout<<"YES"<<endl;
             cout<<a+1<<" "<<b+1<<endl;
        }
      //  cout<<a<<" "<<b<<endl;
    }

    return 0;
}