#include <bits/stdc++.h>   using namespace std;   long long leftBinarySearch(long long* color, long long size, long long target) {     int l = 0;     int r = size - 1;     int idx = -1;     while (l <= r) {       int m = l + (r - l) / 2;       if (color[m] <= target) {         l = m + 1;         idx = m;       } else {         r = m - 1;       }     }     return idx;   }   long long rightBinarySearch(long long* color, long long size,                               long long target) {     int l = 0;     int r = size - 1;     int idx = -1;     while (l <= r) {       int m = l + (r - l) / 2;       if (color[m] >= target) {         r = m - 1;         idx = m;       } else {         l = m + 1;       }     }     return idx;   }   int main() {     int t;     cin >> t;     while (t--) {       long long r, g, b;       cin >> r >> g >> b;       long long red[r], green[g], blue[b];       for (int i = 0; i < r; i++) cin >> red[i];       for (int i = 0; i < g; i++) cin >> green[i];       for (int i = 0; i < b; i++) cin >> blue[i];       sort(red, red + r);       sort(green, green + g);       sort(blue, blue + b);       long long ans = LLONG_MAX;       long long left, right;       for (int i = 0; i < r; i++) {         left = leftBinarySearch(green, g, red[i]);         right = rightBinarySearch(blue, b, red[i]);         if (left != -1 and right != -1)           ans =               min(ans, (green[left] - blue[right]) * (green[left] - blue[right]) +                            (red[i] - green[left]) * (red[i] - green[left]) +                            (red[i] - blue[right]) * (red[i] - blue[right]));         left = leftBinarySearch(blue, b, red[i]);         right = rightBinarySearch(green, g, red[i]);         if (left != -1 and right != -1)           ans =               min(ans, (blue[left] - green[right]) * (blue[left] - green[right]) +                            (red[i] - blue[left]) * (red[i] - blue[left]) +                            (red[i] - green[right]) * (red[i] - green[right]));       }       for (int i = 0; i < g; i++) {         left = leftBinarySearch(red, r, green[i]);         right = rightBinarySearch(blue, b, green[i]);         if (left != -1 and right != -1)           ans = min(ans, (red[left] - blue[right]) * (red[left] - blue[right]) +                              (green[i] - red[left]) * (green[i] - red[left]) +                              (green[i] - blue[right]) * (green[i] - blue[right]));         left = leftBinarySearch(blue, b, green[i]);         right = rightBinarySearch(red, r, green[i]);         if (left != -1 and right != -1)           ans = min(ans, (blue[left] - red[right]) * (blue[left] - red[right]) +                              (green[i] - blue[left]) * (green[i] - blue[left]) +                              (green[i] - red[right]) * (green[i] - red[right]));       }       for (int i = 0; i < b; i++) {         left = leftBinarySearch(red, r, blue[i]);         right = rightBinarySearch(green, g, blue[i]);         if (left != -1 and right != -1)           ans = min(ans, (red[left] - green[right]) * (red[left] - green[right]) +                              (blue[i] - red[left]) * (blue[i] - red[left]) +                              (blue[i] - green[right]) * (blue[i] - green[right]));         left = leftBinarySearch(green, g, blue[i]);         right = rightBinarySearch(red, r, blue[i]);         if (left != -1 and right != -1)           ans = min(ans, (green[left] - red[right]) * (green[left] - red[right]) +                              (blue[i] - green[left]) * (blue[i] - green[left]) +                              (blue[i] - red[right]) * (blue[i] - red[right]));       }       cout << ans << endl;     }   }